Eugene
Eugene

Reputation: 5543

How to pass values from Thread Group to TearDown Thread Group?

I'm trying to implement Load Test test script, which should act according to the scenario:

Currently, I'm stuck on database clean up. I can obtain record ID using JSON extractor after sending "producer" request, and use this ID to simulate file download. But this ID isn't visible inside the Tear Down Thread Group.

Could you tell me, how I can pass value from Thread Group which uploads file to Tear Down Thread Group?

Currently, my JMeter 4 project use objects with following configurations:

  1. Producer Thread Group #1 (this thread group uploads and downloads file)
    • POST HTTP request (this request uploads file)
    • JSON extractor
      • Names of created variables = id_to_delete
      • JSON Path expression = $.record-id
      • Match No. = -1
    • GET HTTP request (this request downloads file)
  2. Producer Thread Group #2
  3. Producer Thread Group #3
  4. ...
  5. TearDown Thread Group.

Upvotes: 0

Views: 1783

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

As per JMeter User Manual:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

So you have to go for JMeter Properties to pass the values between Thread Groups, like:

  • To set the property: use __setProperty() function
  • To get the property value in the another Thread Group use __P() function
  • To set user-specific (per-thread) property use __threadNum() function as property prefix of postfix

Example setting property:

${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}

Example getting property:

${__P(foo_${__threadNum},)}

Demo:

JMeter Property Sharing Between Thread Groups

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

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58812

JMeter variables can't be shared between Thread groups (include TearDown),

You can copy variable value to JMeter property and use it in Tear Down, for example inside JSR223 Sampler

props.put("id_to_delete", vars.get("id_to_delete"));

or use __setProperty function to copy value to property:

${__setProperty(id_to_delete, ${id_to_delete},)}

Upvotes: 1

Related Questions