jmeterduplicatesuuidpreprocessorjsr223

How to generate/pass unique UUID to Threads independent of each other in JMeter's Stepping Thread Group


Issue Description

I have a script with 2 different samples nested inside a Stepping Thread Group (Not the usual Thread Group). Each sample has a JSR223 PreProcessor that has a small code to generate UUID.

My expectation is for the JSR223 PreProcessor to generate a fresh new unique UUID for each thread for every new iteration.

However, in my situation, the UUID is not refreshed and is duplicated across all threads and all iterations.

This problem occurs only in Stepping Thread Group and not in normal Thread Group.

So, my ask is how can I generate fresh new unique UUID for each Threads and Iterations in JMeter?

What I've done so far?

For 1st Sample, I am using JSR223 PreProcessor to generate a UUID and store it in string 'ref1'. Then I'm assigning the value from 'ref1' to new variable called 'reference_1' so that I can pass it in the request. Please check the screenshot below for reference.

Jmeter Sampler: enter image description here

Jmeter Listner Output: enter image description here

For 2nd Sample, I'm doing the same steps to generate UUID, but now, I am passing this 2nd UUID in the 2nd sample and also correlating the 1st UUID to the 2nd Sample.

If it helps, I've added a very simple demonstration of what I am Expecting vs what I'm getting: Expectation vs Actual (simplified) enter image description here

Any help is highly appreciated. Thank you!


Solution

  • If you read JMeter documentation (who reads documentation in 2024 anyway?)on JSR223 Sampler you will see the following text there

    The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:

    • Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.
    • Or Use Script Text and check Cache compiled script if available property. When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.

    So you either need to put the __UUID() function to "Parameters" section like:

    enter image description here

    or generate the UUID without calling the function like:

    String ref1 = UUID.randomUUID().toString()
    

    More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?