LeosSire
LeosSire

Reputation: 103

JMeter variable updates ignored in child while loop

I have a test which runs using a Websocket. I have 2 messages I need to write to the websocket and listen to the response (appending message's and closing listener when EOF returned. It works fine with a single message but when I try running with 2 it falls over.

Process (>'s for loop depth):

  1. Loading tokens, load questions, do WS handshake, set variable questionCounter = 0, done = "false" (all works as expected)
  2. Add Loop Controller (loop count 2)
  3. > Add Counter for tracking [var name is counterA]
  4. >Add JSR223 script for setting a variable questionCounter = 1 (Added this script as part of debugging and trying other solutions)
  5. >[Added a timer of 300ms in case there was delays in saving vars in the above script] (getting desperate and trying everything)
  6. >Send request to WS (Write Sampler) (works as expected when reviewing results in Results Tree - yay [I'm using the loop counter counterA from step 3 for getting correct question]

Problems start:

  1. >While Controller closing when done = "true"
  2. >>Add Counter for the While Controller called counterB
  3. >>Read Sampler gets results as expected when viewing responses in Results Tree

9A. >>>Regex Extractor for type in responses with results in type_${question_counter}

9B. >>>Regex Extractor for target in responses with results in target_${question_counter}

9C. >>>Regex Extractor for messages in responses with results in messages_${question_counter}

[Yes I have 3 separate Extractors as I don't know the order the props come in the resposne]

  1. >>JSR223 Script to append the messages above and save them to props but when saving these against a key which uses either questionCounter or counterA it always uses 1 for questionCounter as set in step 4 (ignoring questionCounter++ and a vars.put) and counterA = 0, even on the second loop iteration (where it should be 1).

  2. >>JSR223 Script to check the targets and types to see if the "EndOfMessages" has been sent, if so it closes while counter done = 'true' [again all the regex results are saving against counterA's 0 or questionCounter's `1 from the first loop, even on the second loop]

  3. Then after the loop controller does some logging etc.

I can see from Debug Sampler's and View Results Tree's the "supposedly" updated messageCounter and counterA don't change value. I have log.info's before and after the While Controller for the same log.info("question_counter ${vars.get("question_counter")}") which shows '2' then '1'.

The above misses out lots of Debug Samplers and logging, but I can see from Results Tree and the console window it's not updating.

I have tried swapping in the counterA from the parent loop with a manually set questionsCounter and neither are updating inside the While Loop.

Why is the loop ignoring the updated values?

Many thanks in advance.

Upvotes: 0

Views: 26

Answers (1)

Ivan G
Ivan G

Reputation: 2872

Unfortunately your question doesn't provide sufficient level of details in order to be reproduced (at least for me). I can think of the following enhancements, maybe one of them will help you to proceed:

  1. You don't need any "counters", While Controller exposes a special variable which contains current iteration number:

    enter image description here

    it can be accessed as ${__jm__While Controller Name Here__idx}

  2. Don't inline JMeter functions or variables in form of ${something} into Groovy scripts because only first value will be compiled and cached, see JSR223 Sampler documentation for more details

If you still experience issues please come up with a minimal reproducible example using i.e. Dummy Samplers and share the full test script.

Upvotes: 1

Related Questions