Yevhen Tokarenko
Yevhen Tokarenko

Reputation: 23

Jmeter. How to pass a variable generated by each user in thread to second thread users?

Good day, guys! What I attempting to do is perform a clean logout for all users after test stops running via duration restriction. In my case, when user logs in, he gets unique session id parameter that makes it impossible to log with same user from different tab/browser/place, so I need to be sure that user is not blocked after my test completes.

Lets say I use 100 users for a test.

My test looks something like:

It works fine when I use a constant set of loops, but when I run test with duration, for example, 600 seconds, test stops in the middle after time runs out and my users are blocked until their sessions expire by timeout.

I tried to create a second thread which also contains 100 users and only a logout HTTP sampler, passed and used session id variable to it as described in article https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups but it seems that my second thread receives only a last session id value so it basically logs out 1 user 100 times, but I need to log out 100 users 1 time.

Does anyone now how to store multiple values of a variable and use them in correct order in other threads?

Not a programmer, just a manual tester with some extra responsibilities. Thank you.

Upvotes: 2

Views: 2735

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

JMeter Variables are local to each thread, JMeter Properties are global for the whole JVM so if you're passing variables between thread groups make sure you add current thread number as a prefix (or postfix) for the generated property, something like:

  1. In the first Thread Group define user-specific property using __setProperty() and __threadNum() functions combination:

    ${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}
    
  2. In the second Thread Group get user-specific property using __P() and __threadNum() functions combination:

    ${__P(foo_${__threadNum},)}
    
    • Replace foo with the property name of your choice
    • Replace YOUR_VARIABLE_HERE with the name of the relevant JMeter Variable

Demo:

JMeter User Specific Properties

See Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

Upvotes: 4

Related Questions