JMeter check different assertion on different threads

六眼飞鱼酱① 提交于 2019-12-12 01:48:12

问题


Using JMeter, I want to check locking section that allow only 1 update

I'm running Thread group with 10 Threads and expect only 1 (not always the first) thread to return 0 and 9 others to return 1 How can I assert it?

Thread group (10) - HTTP Sampler - - ? Assertion

Edit

10 is actually a dynamic property. So I need for any thread count to expect only 1 assertion to return success.

The test is to check that locking of record is working and can only update record once, even on stress/load test.

Edit 2

Using Critical Section Controller didn't give me exact result of failures


回答1:


I can see 2 ways of implementing your scenario:

  1. Use AutoStop Listener available via JMeter Plugins, it has AutoStop on Error Rate feature so you will be able to stop your test if the percentage of failed samplers will be higher than 90. You can install AutoStop Listener using JMeter Plugins Manager:

  2. Use Taurus tool as a wrapper for your JMeter test, Taurus has Pass/Fail Criteria subsystem where you can put your logic to conditionally fail the whole test if error rate for a single page will be over 90%. Taurus will return non-zero exit code which you can use later on (i.e. to trigger build failure in continuous integration server).




回答2:


Finally I succeeded, I save each thread in a unique id the failure count and I use tearDown Thread Group at the end to calculate the failures

In Thread Group after request check for invalid response with If Controller

and under it JSR223 Sampler which mark failures flag by unique id per thread:

String threadNumber = String.valueOf(ctx.getThreadNum());
props.put("failures" + threadNumber, 1);

JSR223 Sampler will failed unless only exactly one successful request exists

int numberOfFailures = 0;
for (i=0; i < 10; i++) {
    String id = "failures"+ String.valueOf(i);
    failureFlag = props.get(id);
    log.info("failureFlag=" + failureFlag);
    if (failureFlag == 1){
        numberOfFailures ++;
    }
}
if (numberOfFailures != 9) {
    SampleResult.setSuccessful(false);
}


来源:https://stackoverflow.com/questions/43473310/jmeter-check-different-assertion-on-different-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!