Stop JMeter test execution only after n assertion errors

血红的双手。 提交于 2020-02-03 19:07:03

问题


Problem

I am modelling stress tests in JMeter 2.13. My idea of it is to stop the test after certain response time cap is reached, which I test with Duration Assertion node.

I do not want, however, to stop the test execution after first such fail - it could be a single event in otherwise stable situation. I would like the execution to fail after n such assertion errors, so I can be relatively sure the system got stressed and the average response should be around what I defined as a cap, which is where I want to stop the whole thing.

What I tried

I am using Stepping Thread Group from JMeter plugins. There I could use a checkbox to stop the test after an error, but it does that on first occasion. I found no other node in documentation that could model it, so I'm guessing there's a workaround I'm not seeing right now.


回答1:


Close but not exactly what you're asking for: The Auto-Stop Jmeter plugin. See the documentation here. You can configure it to stop your test if there are n% failures in a certain amount of time.

If you want a specific number of errors, you can use a test-action sampler, combined with an if-controller - if (errorCount = n) test-action stop test




回答2:


I would recommend switching to Beanshell Assertion as it is more flexible and allows you to put some custom code in there.

For instance you have 3 User Defined Variables:

  • threshold - maximum sampler execution time. Any value exceeding the threshold will be counted
  • maxErrors - maximum amount of errors, test will be stopped if reached and/or exceeded
  • failures - variable holding assertion failure count. Should be zero in the beginning.

Example Assertion code:

long elapsed = SampleResult.getTime();

long threshold = Long.parseLong(vars.get("threshold"));

if (elapsed > threshold) {

    int failureCount = Integer.parseInt(vars.get("failures"));
    failureCount++;

    int maxErrors = Integer.parseInt(vars.get("maxErrors"));

    if (failureCount >= maxErrors) {
        SampleResult.setSuccessful(false);
        SampleResult.setResponseMessage(failureCount + " requests failed to finish in " + threshold + " ms");
        SampleResult.setStopTest(true);
    } else {

        vars.put("failures", String.valueOf(failureCount));
    }
}

Example assertion work:

See How to use BeanShell: JMeter's favorite built-in component guide to learn more about extending your JMeter tests with scripting.



来源:https://stackoverflow.com/questions/29799841/stop-jmeter-test-execution-only-after-n-assertion-errors

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