3

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:

  • My JMeter version: 5.3
  • Groovy version: 3.0.3
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Keet Sugathadasa
  • 11,595
  • 6
  • 65
  • 80

2 Answers2

4

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:

  • prev.setStopTest(true) - to gracefully "ask" threads to stop
  • prev.setStopTestNow(true) - to forcefully "tell" threads to stop (you might get extra errors connected with abnormal threads interruption)
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
2

You can use prev to stop test

 prev.setStopTestNow(true);

stop the test now interrupting current running samplers

prevĀ - (SampleResult) - gives access to the previous SampleResult (if any)

For a more sudden and abnornal exit, you can exit Java process

 System.exit(1);
Ori Marko
  • 56,308
  • 23
  • 131
  • 233