0
votes

I'm trying to set up a JMeter run that does this:

  1. Make Rest API request
  2. Use a JSON Extractor to check the response for a given array of values.
    • I define success as all of the "Items[*].Success" nodes equaling "true"
  3. If the response is successful, break out of the loop (continue to step #5)
  4. If the response is a failure, go back to step #1
  5. ... the rest of my test steps

Here's what I've set up to do this:

  1. Use a BeanShell Assertion to initialize a loop variable:
    • ${__setProperty(is_any_calc_pending,true)};
  2. While Controller with a condition set to
    • ${__BeanShell(props.get("is_any_calc_pending")}
    • My problem is here, the loop never stops
  3. Make Rest API call (This works as expected)
  4. JSON Extractor (This also works as expected)
    • Names of created variables = api_successes
    • JSON Path expressions = $.Items[*].Success
    • Match No. = -1
    • Compute concatenation = checked
    • Default Values = unset_api_successes
  5. JSR223 PostProcessor set to Javascript to update the value of the loop variable.

Here's my code for step #5. It simply checks whether or not there's a "false" in the api_successes_ALL variable that the JSON Extractor creates.

var api_successes_ALL = vars.get('api_successes_ALL')
var all_successful = api_successes_ALL.indexOf('false') < 0
props.put('is_any_calc_pending',!all_successful)

Most of this works as I expect; I can check this using the Debug Sampler. The problem I'm having is that the loop never stops. The condition never causes the loop to break.

In the log, I see this line:

DEBUG o.a.j.c.WhileController: Condition value: 'false'

The documentation says that the While Controller will continue until the condition is false. From what I see in the log, the condition is always false. I also don't understand why the While Controller never sees that the value of my is_any_calc_pending changes. I can see in the Debug Sampler that the value changes.

Is the variable being re-initialized somehow? I'm wondering if my variable or property is going out of scope.

1

1 Answers

0
votes

I got it. Here's what I did:

  • Simple Controller (I'm not sure if this is necessary)
    • Make Rest API call to initiate process
    • While Controller, see condition code below
      • Make Rest API call to check status
      • JSON Extractor with the same property values I listed in my question

I didn't expect it, but the While Controller has access to the variables generated in the JSON Extractor. I think the Simple Controller may have caused this.

While Controller condition. I left the log.warn() call in there to show how I debugged the condition.

${__javaScript(
    log.warn( vars.get("api_successes_ALL") );

    !!vars.get("api_successes_ALL") ?
    (vars.get("api_successes_ALL").indexOf("false") >= 0) :
    "true";
)}