groovyjmeterthreadgroup

JMeter Scripts - Stop All Thread Groups (Entire Test) based on a condition


I have a JMeter script with multiple thread groups which are running concurrently. In one thread group PostProcessor, I would like to check for a condition and stop ALL thread groups, and exit. Basically, I want to stop the entire test.

if (Integer.valueOf(prev.getResponseCode()) >= 400) {
    // Stop the entire test in the next line.   
}

How can I stop all thread groups at once, in a JMeter Script?

Please see:


Solution

  • JMeter automatically treats HTTP Request samplers with status codes above 400 as failed so you don't have to go for scripting, you can stop the test using If Controller using the following condition:

    ${__jexl3("${JMeterThread.last_sample_ok}"=="false",)}
    

    and add Flow Control Action sampler as a child of the If Controller

    enter image description here

    If you want to do this in Groovy - go for one of the following approaches: