0
votes

I want to have a global variable for inter thread communication.

Current setup:

Thread Group 1: It is a multi-user thread, that will be accessing certain API's in a flow.

Thread group 2: Now, as per our current system, the auth-token refreshes after every 10 min. So in this thread group, I am calling refreshToken API.

Approach1: Tried using jmeter property. But since all threads are in parallel, so if one thread updates the token, all other threads fail.

Approach2: Using InterThreadCommunication plugin. Since I don't know when and where in the system, the token will expire, so don't know where to call in the inter thread communication pre-processor.

enter image description here

2

2 Answers

1
votes

Use thread-specific properties like:

  1. In "Refresh Token" Thread Group specify individual properties to hold tokens for each virtual user like:

    ${__setProperty(token_${__threadNum},YOUR_TOKEN_VALUE_HERE,)}
    
  2. In "PA APIs" Thread Group access individual token values like:

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

References:

0
votes

In approach 1 with jmeter property you can continue with adding a Critical Section Controller with same key as a parent for Samplers who is trying to get or refresh your token.

That way Threads will wait until previous (get/)update token will be over and then get the updated token.

Notice that it won't work in Distributed testing:

Critical Section Controller takes locks only within one JVM, so if using Distributed testing ensure your use case does not rely on all threads of all JVMs blocking.