JMeter - Pause the request if it gives an error

Viewed 157

I'm using Apache JMeter to send thousands of HTTP requests with 3 seconds of delay in between. The response body is json and starts with {"errors":[ ], ...}. If there is an error it will be in the [ ]. If there is no error than [ ] will be empty.

I want JMeter to pause for a short period of time if it receives an error, and try the request again. So that it'll add in additional buffer when needed.

Do I need a script for this? How can I achieve this?

2 Answers

Solution 1

Add a JSR223 Post Processor to the Test Plan level, Thread Group or to a sampler based on your requirement.

Add following code into the script area to check the error and introduce a delay after error if any.

int delayOnErrorInMillis = 5000

if (prev.getResponseDataAsString().startsWith('{"errors":')){
    log.info("ERROR !")
    sleep(delayOnErrorInMillis)
}

enter image description here

Related