-
Notifications
You must be signed in to change notification settings - Fork 0
Using properties
Properties in DTF are the variables of the language and they follow a few simple rules:
This rule is imposed so that you can easily drive your test execution from the command line. The idea is that all properties should be easily controlled from the command line and only those properties that you use within your test to count or keep track of certain runtime values are to be overwritten using the overwrite attribute, which in turn makes that property a variable within your test. So if you write a simple test like so:
<?xml version="1.0" encoding="UTF-8"?>
<script xmlns="http://dtf.org/v1" name="simple_for_test">
<info>
<author>
<name>Rodney Gomes</name>
<email>rlgomes@yahoo-inc.com</email>
</author>
<description>
Simple for loop test used in the Language Basics documentation section.
</description>
</info>
<property name="iterations" value="10"/>
<for property="i" range="1..${iterations}">
<log>${i}</log>
</for>
</script>The above test when executed as designed will execute 10 times and if you want to change that from the command line a simple -Diterations=100, like so:
./ant.sh run_dtfx -Ddtf.xml.filename=tests/examples/simple_for_test.xml -Diterations=100
With this you can see how you can easily control the number of clients being used and the exact load being generated by a test from the command line without having to edit files. This makes automating test execution and changing everything from the number of iterations to execute or the number of clients to use, to being able to actually change the format of your results being tested or if certain things such as validation, statistics are to be calculated during this particular run.
This allows you to do some very complex things with your properties such as:
<?xml version="1.0" encoding="UTF-8"?>
<script xmlns="http://dtf.org/v1" name="recursive_property_resolution">
<info>
<author>
<name>Rodney Gomes</name>
<email>rlgomes@yahoo-inc.com</email>
</author>
<description>
Simple for recursive property resolution test used in the Language
Basics documentation section.
</description>
</info>
<property name="iterations" value="10"/>
<createrange name="range1" value="1,2,3,4,5"/>
<createrange name="range2" value="10,11" recycle="true"/>
<createrange name="range3" value="32,33,34,35,36"/>
<parallelloop property="t" range="1..5">
<for property="i" range="1..3">
<log>Thread ${t} has ${range${i}}</log>
</for>
</parallelloop>
</script>The above example shows how to use the recursive resolution of properties to actually reference another range by its name in a dynamic way at runtime. This can allow you to do a lot of things such as pulling values from certain properties by the name of the user being currently used in a test or some other variable that defines an important element of the execution.
When using properties you don't have to worry about accessing them from multiple threads because the thread isolation is handled by the framework. One thing to take into account is that writing to a property is only visible to that thread so the parent thread (or main thread) does not see those changes from any of the threads. The only way currently to communicate back to the parent thread is to throw an event with the event tag and then there will be a property with the name of the event and all fields attached to that event visible in the parent thread.
<?xml version="1.0" encoding="UTF-8"?>
<script xmlns="http://dtf.org/v1" name="thread_property_usage">
<info>
<author>
<name>Rodney Gomes</name>
<email>rlgomes@yahoo-inc.com</email>
</author>
<description>
Simple for threaded property test used in the Language Basics
documentation section.
</description>
</info>
<property name="iterations" value="1000"/>
<property name="count" value="0"/>
<parallelloop property="t" range="1..5">
<for property="i" range="1..${iterations}">
<add op1="${count}" op2="1" result="count"/>
</for>
<assert><eq op1="${count}" op2="${iterations}"/></assert>
<log>thread ${t} is done.</log>
</parallelloop>
</script>