JMeter - Pause threads for a random number of seconds when a specific code is returned from an API call

Software Quality Assurance & Testing Asked by M Thurman on December 25, 2020

I have a situation where I need to pause all of the threads to a particular endpoint when I receive a specific error code from the response. So I basically need to look for this error code (ex. 404) and pause for a random num of secs b/t 3 and 10. Below is my current test structure. I have looked at the logic controllers but I am unsure how to implement. I assume that I would need to wrap each request with this logic. Thanks for your help!

  • Test Plan
    • Thread Group
      • CSV Data Set Config
      • HTTP Request 1
      • HTTP Request 2
      • Summary Report


One Answer

  1. Add Regular Expression Extractor as a child of the HTTP Request sampler which code you need to extract and configure it as follows:

    enter image description here

    it will save response code of the sampler into ${code} JMeter Variable

  2. Add If Controller after this sampler and use the following __jexl3() expression:


    it means that If Controller's children will only be executed if the Sampler will fail with 404 status code

    enter image description here

  3. Add Flow Control Action sampler as a child of the If Controller and configure it as follows:

    enter image description here

    this ${__Random(3000,8000,)} function will generate random think time between 3000 and 8000 milliseconds which seems to be exactly what you're looking for

Answered by Dmitri T on December 25, 2020

Add your own answers!

Related Questions

Proper way to use throwaway email addresses for testing

7  Asked on December 13, 2020 by nikhita-jalan


Issue with switching / clicking an iFrame jmeter selenium

1  Asked on September 5, 2020 by chathud


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir