0
votes

I have a JMeter script which makes requests to 5 different endpoints. If there's an error, that thread should be stopped.

However, I would like to retry the request to the 3rd endpoint 3 times before stopping the thread.

Here is what my script looks like:

  • Thread Group (with Stop thread selected)
    • HTTP Request (1st endpoint)
    • HTTP Request (2nd endpoint)
    • Transaction Controller
      • While Controller
        • HTTP Request (3rd endpoint)
          • JSR223 PostProcessor (to save the response code in a variable for the while controller to check)
        • Counter (to keep track of the retry count)
      • JSR223 Assertion (to set the result as successful, so the first failed retries don't count)
    • HTTP Request (4th endpoint)
    • HTTP Request (5th endpoint)

Since I checked option Stop thread under Thread Group, if the first request to the 3rd endpoint fails, the thread stops and no retries are made.

If I check Continue, then the retries to the 3rd endpoint work as intended, but the thread doesn't stop if the requests to the other endpoints fail.

I also tried to add the following Groovy script to the JSR223 PostProcessor, but it didn't work:

if (prev.isStopThread()) {
    prev.setStopThread(false)
}

I'd appreciate any help I can get.

Thank you!

1

1 Answers

1
votes

Just set "Action to be taken after a Sampler error" to Continue in the Thread Group to prevent threads from stopping.

If you decide to stop the thread you can do it in 2 ways:

  1. Via Flow Control Action Sampler (in conjunction with the If Controller)

    enter image description here

  2. Via any of your JSR223 Test Elements as

    prev.setStopThread(true)
    

You don't even need a counter, since JMeter 5.0 While Controller exposes current iteration via __jm__While Controller__idx pre-defined variable