4

Imagine I have a simple test plan, like so:

setUp Thread Group
-- Http Request
---- JSON Extractor

Thread Group
-- Http Request

tearDown Thread Group
-- Http Request

By default, the variables extracted in the setUp Thread Group will not be accessible within the ordinary Thread Group nor the tearDown Thread Group. The variables' contents are different for each user and cannot be precomputed and loaded into the test plan. It is not possible to simulate the correct load using a single user.

How can I access each thread's setUp variables from within the corresponding Thread Group proper and tearDown?

lpd
  • 2,151
  • 21
  • 29

2 Answers2

7

JMeter Variables scope is limited to current Thread Group only, if you need to pass some data between different Thread Groups you need to convert JMeter Variables into JMeter Properties:

More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Properties are global right, they wouldn't be individual to each user? – lpd Jul 26 '17 at 07:50
  • Yes, properties are global for the whole JVM, if you need them to be user-specific you can use i.e. [__threadNum() function](https://guide.blazemeter.com/hc/en-us/articles/206733739-Using-JMeter-Functions-Part-II) as prefix or postfix so virtual user #1 would have one value, virtual user #2 another value, etc. – Dmitri T Jul 26 '17 at 07:58
  • Can you provide an example of how that might work? Is there either a performance or coded limit to the amount of properties that can be set in this way? – lpd Jul 26 '17 at 08:03
  • Here you go: https://i.stack.imgur.com/632vw.png. You may also find [Inter-Thread Communication](https://jmeter-plugins.org/wiki/InterThreadCommunication/) plugin interesting, it can be used for passing variables between different JMeter threads and even thread groups. You can install the plugin using [JMeter Plugins Manager](https://www.blazemeter.com/blog/how-install-jmeter-plugins-manager) – Dmitri T Jul 26 '17 at 08:17
  • Thanks, that's working for 2 threads. I'm still concerned about scale though, what happens at say 5000 distributed threads? That plugin appears to implement a queue, which would be great for one variable but not for transferring multiple variables, without implementing custom code to combine and split them. – lpd Jul 26 '17 at 08:59
1

You stated in comments

5000 distributed threads.. transferring multiple variables...

Maybe JDBC Requests will help you to save(insert) variable to database and get(select) variable and delete/update variable wherever you are in test.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I imagine that may perform better, yeah, although it's still alot of seemingly unnecessary synchronisation for individual threads that retain the same thread id (eg 1-1, 1-2) throughout all 3 stages. Not to mention the effort of setting this db up... – lpd Jul 27 '17 at 06:47