Search code examples
jmeterhttprequest

JMeter - Pause the request if it gives an error


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?


Solution

  • You can get the number of errors by adding a JSON JMESPath Extractor as a child of the Sampler which returns the JSON and configuring it like:

    enter image description here

    It will extract the number of entries in errors JSON Array and store it into errors JMeter Variable

    Then you can use If Controller to check if the number of errors is above zero, it can be done using __jexl3() function like:

    ${__jexl3(${errors} > 0,)}
    

    enter image description here

    and finally you can introduce a delay using Flow Control Action sampler:

    enter image description here