Nitesh Sharma
Nitesh Sharma

Reputation: 555

Jmeter : using While Controller for failed request retries, ThreadGroup loop count not working

I added a While Controller and try to send this request multiple times in case if it doesn't work the first time or simply just trying to implement retry logic.

Thread Group configurations are :

  1. Threads (Users) - 1
  2. Loop - 10

Issue: As per thread group config, it should run ( while controller * 10 ) but it only runs 1 time.

enter image description here

In my Bean PostProcessor :

vars.remove("response_code");
vars.put("response_code",prev.getResponseCode());

In WhileController :

${__jexl3(${response_code} != 200 && ${retries} < 3,)}

Any help would be appreciated!

Upvotes: 1

Views: 1248

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

On 2nd iteration of your Thread Group your ${response_code} variable becomes 200 therefore it will not enter the While Loop.

The solution is to reset both ${response_code} and ${retries} variables to 0

  1. Add JSR223 Sampler to be the first Sampler in your Thread Group
  2. Put the following code into "Script" area:

    SampleResult.setIgnore()
    vars.put('response_code', '0')
    vars.put('retries', '0')   
    

Also be aware that starting from JMeter 3.1 you shouldn't be using Beanshell so consider migrating from the Beanshell PostProcessor to the JSR223 PostProcessor. More information: Apache Groovy - Why and How You Should Use It

Upvotes: 1

Related Questions