0
votes

I have to implement a scenario where i have to call the same request at max for 5 times if it fails and based on the response i am writing some thing in a file. Failure happens when a string is not found from cookie which i am capturing as regular exp.

To resolve this , i have added while loop with counter but the script works till 50000 iteration and then gives Out of memory error. If i dont put while loop to recall the same request for 5 times, then same script works for 1 million with same JVM without any issue.

Looks like While controller in Jmeter is somehow consuming more memory and throwing out of memory.

Is there any option to recall the same HTTP request through Beanshell Post processor?

1

1 Answers

0
votes
  1. Approach using While Controller and Counter combination:

    • While Controller: condition ${__javaScript(${counter} < 5 && "${foo}" != "bar",)}
      • Counter: Start 1, Increment 1, Reference Name counter
      • Your Sampler

    Assuming above setup Your Sampler will be executed either 5 times or until when ${foo} variable value not equal to bar, whatever comes the first. See Using the While Controller in JMeter for comprehensive explanation and more examples.

  2. If you are still looking for Beanshell way you can use something like:

    if (!prev.getResponseDataAsString().contains("foo")) {
        ctx.getCurrentSampler().sample(null);
    }
    

    Above code being placed into Beanshell PostProcessor will execute the parent sampler one more time if there will not be foo substring in the response, however this way you won't be able to see execution result in listeners and it won't be stored into .jtl file, basically you will have only one execution.