0
votes

On a http response for a http request I am checking a particular field from one status to another status using a while controller. But the while controller is not breaking the loop even after the condition is satisfied.

{
    "data": {
        "uri": null,
        "taskId": "f5b6aaf3-8b14-49ba-a495-788eef5c523b",
        "taskStatus": "Ongoing"
    },
    "apiUrl": "http:\/\/.int:8081\/release01-nightly-api\/\/2192_IND_1_40",
    "statusCode": "102"
}

So the above response "taskStatus": "Ongoing" which will be "Successfull" after some time may be 20-30 seconds so I have used a while controller, which is not breaking even after the condition is satisfied.

Here below the details of while controller, enter image description here I am fetching the status using a JSON extractor enter image description here Execution snapshot, enter image description here What I am doing wrong here

2

2 Answers

2
votes

Your expression is wrong, change it to:

${__groovy((!vars.get('task_status').equals('Success') && (vars.get('__jm__While Controller__idx') as int ) < 30),)}

no other changes are required.

Going forward use Debug Sampler to evaluate your expressions

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

0
votes

Few things configured wrongly, encountered with similar situation this is the solution we implement,

  1. First http request with json extractor seems fine. [No changes needed]

  2. Now in the while controller please do the changes ${__javaScript("${task_status}"!="Success" && parseInt(vars.get("statusCounter"))<=30)}

  3. Under the while controller start a counter with the following values

    starting value: 0

    increment: 1

    exported variable name : statusCounter [give this name according to your choice]

  4. Under the while controller put the same http request and add a json extractor similar to step 1.

  5. Under this request add a beanshell assertion and following code,

Code Block for the assertion:

try {
    if (vars.get("task_status").equals("Success")) {
        Failure = true;
        FailureMessage = "Workflow Status is not changed : " + vars.get("task_status_Upd");
        SampleResult.setStartNextThreadLoop(true);
    }

    if (vars.get("statusCounter") == 30) {
        Failure = true;
        FailureMessage = "RequestTimeOut";
        SampleResult.setStartNextThreadLoop(true);
    }
} catch (Exception ex) {
    log.info("Error in beanshell", ex);
    throw ex;
}