How to stop Jmeter test after specified number of threads has failed
I have one transaction controller that has one HTTP request in my Jmeter test plan. The transaction name and URL comes from a CSV file. At the end, the total execution is divided into 5 different transactions.
Testplan:
Testplan -Thread Group - Custom variable
The total sample execution will be 8000-10000. Now what I want is, if the total fetch failures reached 100, my JMeter test should stop running the test.
I added User defined variable name "thread" and with value "0". I added below code in Beanshell Post Processor
int count= Integer.parseInt(vars.get("thread"));
if (prev.getErrorCount()==1){
count++;
System.out.println(count);
vars.put("thread",Integer.toString(count));
}
if (count==100){
System.out.println("Reached to max number of errors in load test, stopping test");
log.info ("Reached to max number of errors in load test, stopping test");
prev.setStopTestNow(true);
}
Somehow the code doesn't work as expected. When the error count reaches 100, the Jmeter test does not stop. The test stops when the error count reaches 130. I'm not sure who fix the above code.
Can someone please let me know what is the problem in the above code?
source to share
Variables are specific to 1 thread, while Properties are shared by all threads.
Cm:
Keep access synchronized
Another option is to use custom java class as Singleton and increase its value.
Here's an example implementation using Beanshell (Prefer JSR223 + Groovy for speaking):
-
setupThreadGroup, which resets the counter when the test is run:
-
BeanshellPostProcessor, which updates the counter:
Please note that when you call setStopTestNow, the test threads are interrupted, but do not stop exactly at this time, unless you have a timer (which usually happens)
prev.setStopTestNow (true);
source to share