Search code examples
javajmeterjmeter-pluginsbeanshell

JMeter: Stop test if the fail count rate is higher than success


In JMeter,

I'm creating a test plan

In which I need to set a condition

(if the fail count rate is high than success, then I want my test to stop)

Tried :

  • Auto-stop listener but its useful if we specify error rate %

  • Tried bean shell post-processor but unsuccessful.

    if (!prev.isSuccessful()) { prev.setStopThread(true); }

Any ideas much appreciated.! thanks in advance.!


Solution

  • By calling setStopThread you are "asking" JMeter to attempt to stop current thread only, the correct method would be prev.setStopTest(true). Again, if you call this method JMeter will "ask" threads to stop, if you want JMeter terminate in less graceful manner you can go for prev.setStopTestNow(true) method (you can get more failures this way as samplers will be abnormally terminated)

    And finally you can call System.exit(1) method which will immediately terminate the whole JVM.


    Be aware that since JMeter 3.1 it is recommended to use JSR223 Test Elements and Groovy language for scripting consider migrating from Beanshell to Groovy on next available opportunity.