3

I have one Transaction controller which has one http request in my Jmeter test plan. Transaction name and url comes from CSV file. At the end total execution is divided into 5 different transactions.

Testplan:

Testplan -Thread Group - User defined variable

Total sample execution will be 8000-10000. Now what i want, if total sample failures reached to 100, my JMeter test should stop test execution.

I have added User defined variable name "thread" and with value "0". I have 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 code is not working as expected. When error count reach to 100, Jmeter test is not getting stopped. Test is stopped when error count reached to 130. I am not sure who to fix above code.

Can someone please let me know what is issue in above code?

user1169236
  • 159
  • 1
  • 2
  • 13
  • Do you have nested samples? – Ross Jul 13 '15 at 05:03
  • If i run it for single user and keep error count limit to 3, it works fine. Test stopped after 3 failuers. But when i run it for 5 Users, with max error count s 3, Test stop after 8 failures. It’s simple script. No nested samples. – user1169236 Jul 13 '15 at 05:08
  • Have you tried to use props instead of 'vars'? – Ross Jul 13 '15 at 05:22
  • No i did not. Could you please share some details on that? – user1169236 Jul 13 '15 at 05:23
  • props is global while vars is localised to the thread. Because I can't try it myself I won't recommend it as an answer, but if it works for you I'll can give a better explanation. – Ross Jul 13 '15 at 05:26
  • I am not sure where i need to use props. https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html#getErrorCount()........this api gives me error count. I am storing it in User defined variable which i set to '0' before starting the test. Then i am comparing it with some predefined count. – user1169236 Jul 13 '15 at 05:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83089/discussion-between-ross-and-user1169236). – Ross Jul 13 '15 at 05:28

1 Answers1

3

Variables are specific to 1 thread while Properties are shared by all threads.

See:

Ensure you synchronize access

Another option is to use a custom java class as a Singleton and increment its value.

Here an example implementation using Beanshell (Prefer JSR223 + Groovy for performances):

  • setupThreadGroup that resets the counter on test start:enter image description here

  • BeanshellPostProcessor that updates counter:enter image description here

Note that as you call setStopTestNow, test threads are interrupted but do not stop exactly at this time unless you have some timer (which is usually the case)

prev.setStopTestNow(true);

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
  • Yes i am working on it. But looks like i am doing something wrong. I have added declared as property but still facing same issue String count1 = props.setProperty("abc","0"); String thread = props.getProperty("abc"); int count= Integer.parseInt(vars.get("thread")); if (prev.getErrorCount()==1){ count++; System.out.println(count); vars.put("thread",Integer.toString(count)); } if (count==3){ 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); } – user1169236 Jul 13 '15 at 10:07
  • Thanks a lot for helping me out. Above solution i have tried and it worked :). I appreciate your help. – user1169236 Jul 14 '15 at 05:10