To create a scriptable variable, implement the
StresStimulus.Extensibility.IExternalVariable interface. It has the following interface definition:
This interface has one property and one method:
- The GetValue() method should have all the logic of the scriptable variable and must return the parameter value. If no value (or null value) is returned, then StresStimulus will use the recorded value when sending the request. This method receives a SessionContext object object that describes the iteration and VU context of which this scriptable variable is called from.
- The EvaluateOnIteration property should return true if this scriptable variable has the same value throughout each VU's iteration. This property should only return false if the scriptable variable is used in several requests in the test case and the value is expected to change from request to request.
One instance of the class is created for every parameter in a test case. Here is an example: in a test case a scriptable variable
MyScriptVar is used to create three parameters in 3 different requests. In this case, three instances of the MyScriptVar class are created. They are instantiated at the moments when the scriptable variable is bound to the parameters. This happens when you open the test, or on-demand when you create a parameter in the test designer. There are several consequences of this design:
- Every VU and every iteration during the test will use the same instance of the class associated with the corresponding parameter (3 instances per
MyScriptVarvariable in this case).
- Class level variables persist throughout StresStimulus application session. If you restart the test without closing StresStimulus, the class level variables will be not initialized, which makes them less predictable. In most cases, it makes sense to use local method variables.
- During test runtime,
GetValue()is called when evaluating the corresponding parameters. For example, if you put your test case in a loop which is executed twice, then every VU on every iteration will trigger six
GetValue()is called asynchronously for every VU on every iteration. So if you have 100 VUs each running five iterations the total number of calls will be 100 * 5 * 6 = 3000. This method is not thread-safe, so use locks when using shared resources.
GetValue()call in Stimulus is located within a try/catch block. If your
GetValue()implementation throws an exception, it will be ignored, and the recorded value will be used in StresStimulus to parameterize the request.
GetValue()execution time can have a performance impact on the StresStimulus load generator hit rate. Design
The following is a simple example of creating a parameter that returns a unique time-based id. For more complex examples see the subsequent sections.
- No labels