So S.
So S.

Reputation: 39

JMeter duration assertion Override Response Code

I have a JMeter test plan which executes only 1 HTTP Request for multiple times per Second. As a parameter I have a certain timeout for every request the test executes. For this I have added the "Duration Assertion" Sampler/Listener/ IDK^^

Now I am running the test and I am always getting the response code 200 because the request is OK but the duration assertion is exceeded. That causes that in the results tree there are succeeded and failed requests but all of them have the status code 200. The problem is that in the "Response Codes Per Second" Listener it shows that all requests are OK and have the response code 200. But they are not OK because of the duration assertion!

My Problem: I would like to override the status code of those requests which are failed due to the duration assertion. I want them to be displayed as a different response code (BUT ONLY IF THEY EXCEED THE DURATION ASSERTION) in the "Response Codes Per Second" Listener because I cant distinguish them. Or is there some way I can make them fail when they exceed the timeout?

I am really sorry for my english and I hope that you can understand my problem. Thanks a lot!

Upvotes: 3

Views: 920

Answers (1)

Dmitri T
Dmitri T

Reputation: 168092

I'm not aware of any Test Elements which allow changing Response Code, however you can do it via scripting as follows:

  1. Add Beanshell Assertion as a child of the request you want to fail. The Beanshell Assertion should go after the Duration Assertion

  2. Add the following code to the "Script" area:

    import org.apache.jmeter.assertions.AssertionResult;
    
    AssertionResult[] results = prev.getAssertionResults();
    for (AssertionResult result : results) {
        if (result.isFailure()) {
            if (result.getFailureMessage().contains("The operation lasted too long")) {
                SampleResult.setResponseCode("1000");
            }
        }
    }
    

    Beanshell Assertion Change Response Code

See How to Use JMeter Assertions in Three Easy Steps for more information on conditionally passing/failing JMeter samplers via assertions.

Upvotes: 2

Related Questions