roozbeh_al
roozbeh_al

Reputation: 47

Loop controller inside While controller in JMeter

I have a while controller that stops after running for 5 seconds. This while controller works fine when inside it, there is one sampler or one HTTP request.

Now I want to have a loop controller inside this while controller. But now, the while controller doesn't stop after 5 seconds, and the script runs for the number specified in loop controller.

Is there any way my loop controller stop working when the while controller trigers in 5 seconds?

Here's the schematic of my test plan. I want that "search" request stops after 5 seconds (the condition inside while controller), no matter the specified number in loop controller.

enter image description here

PS. The code inside JSR223 Sampler1 calculates the maximum time:

max = ${__timeShift(,,PT5S,,)}; 
vars.putObject("max", max);  

And this is the logic inside While Controller:

${__groovy( now = ${__time()}; max = vars.get("max") as long; now <= max,)}

Upvotes: 0

Views: 798

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  1. Why would you need the Loop Controller if While Controller generates loops itself?
  2. Don't inline JMeter Functions or Variables into JSR223 Test Elements or __groovy() function otherwise you might get unexpected behaviour.

If you want to limit While Controller's number of loops to some specific maximum value just include it into your condition clause.

  1. In the JSR223 Sampler:

    max = System.currentTimeMillis() + 5000L
    
  2. In the While Controller:

    ${__groovy( now = System.currentTimeMillis(); max = vars.getObject("max"); now <= max && (vars.get('__jm__While Controller__idx') as int) < 10,)}
    

More information: Using the While Controller in JMeter

Upvotes: 1

Related Questions