0
votes

I have a jmeter thread group which uses transaction controller & a while loop controller inside that to run a query to fetch a token from db. while loop controller has below condition - ${__javaScript("${db_data}".indexOf("replay") == -1,)}

This variable db_data is retrieved with a select query result & loop will run until a value is there (inserted with a http request at the start of thread group). My issue is that until loop count in the thread group is 1; it works fine but once loop count is 2 or more, 2nd iteration is breaking the while loop instantly. How can I ensure that each thread loop initiates with variable db_data as null & does not retain the value inserted in previous run?

1

1 Answers

0
votes

It happens because on 2nd and next iterations your ${db_data} JMeter Variable contains replay hence While Controller's condition isn't met anymore.

The solution is to reset the variable in the beginning of the iteration, one of the possible options is adding i.e. JSR223 Sampler as the first sampler in your Thread Group and use the following code:

SampleResult.setIgnore()
vars.remove('db_data')

It will "clear" the ${db_data} variable so your test will be able to re-enter the While Controller on subsequent iterations.

In the above snippet vars stands for JMeterVariables class instance, see the JavaDoc for all available functions and Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands which are available for JSR223 test elements.

Also I would recommend reconsidering using __javaScript() function, its performance is a big question mark, moreover there is no JavaScript language support in latest Java versions so it might be a good opportunity for switching to __jexl3() or __groovy() function instead.