Search code examples
multithreadingjmeterjmeter-plugins

JMeter check different assertion on different threads


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


Solution

  • 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);
    }