jmeterjmeter-5.0jmeter-maven-plugin

JMeter User Defined Variable for enabling Test Duration


I am trying to parameterize the JMeter test so that I can run Load Test, Stress Test as well as Soak Load Test using the same test plan.

In order to do this, I defined the following as User Defined variables (Test Plan -> Add -> Config Element -> User Defined Variables)

numberOfThreads=${__P(numberOfThreads,1)}
rampUp=${__P(rampUp,1)}
loopCount=${__P(loopCount,1)}
schedulerEnabled=${__P(schedulerEnabled,false)}
schedulerDuration=${__P(schedulerDuration,120)}

Now, in the ThreadGroup definition, I am using these variables as

<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Test123" enabled="true">
        <stringProp name="TestPlan.comments">Test for the endpoint GET /test123</stringProp>
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">${loopCount}</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">${numberOfThreads}</stringProp>
        <stringProp name="ThreadGroup.ramp_time">${rampUp}</stringProp>
        <boolProp name="ThreadGroup.scheduler">{schedulerEnabled}</boolProp>
        <stringProp name="ThreadGroup.duration">${schedulerDuration}</stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
      </ThreadGroup>

But when I run the same and pass in values

numberOfThreads=50
rampUp=10
loopCount=-1
schedulerEnabled=true
schedulerDuration=30

(using jmeter-maven-plugin) the first ThreadGroup keeps creating infinite number of threads instead of shutting down the thread groups after 30 seconds.

PS: 30 is an example. When executing Soak Load Test, I will be setting a higher value to the same.

PS: I noticed that LoopController.continue_forever is set to 'false' immaterial whether for Loop Count I check "Infinite" or provide the value 1. When in UI, I check "Infinite", the value of LoopController.loops is set to -1.


Solution

  • I don't think this is the correct way to enable/disable the thread lifetime setting:

    <boolProp name="ThreadGroup.scheduler">{schedulerEnabled}</boolProp>
    

    Instead of trying to enable/disable the thread lifetime setting you could rather play with this schedulerDuration setting itself, for example if you plan to run fixed amount of loops - set the duration to something very big, the maximum value is 9223372036854775807

    Also it should be possible to use Runtime Controller

    If ability to enable/disable the scheduler is something you really need, you will need to amend it in the .jmx script beforehand somehow, i.e. using sed editor. Also Taurus framework has possibility to amend all the properties of all the test elements using simple YAML syntax