HOAB

History of a bug

JMeter and shared variables between thread group

Rédigé par gorki Aucun commentaire

Problem :

I have two thread groups that must be synchronized. I want to use

java.util.concurrent.CountDownLatch

to achieve this.

I read (here, or here) how to synchronize JMeter thread groups (you have to use properties and not variables). Properties can be access in :

  • bsh sampler : bsh.shared.<property name>
  • jsr223 sample : props.put(<property name>)
  • the org/apache/jmeter/util/JMeterUtils.class is the source of these properties.

I add to my test plan an initial element in bsh, jsr223 to create the latch. But when I get the latch in the thread groups, I always had different instance of my shared latch.

Solution :

Easy when we know.

I made the mistake to add the piece of code in a Pre-Processor

  • Test Plan
    • PreProcessor BSH : init latch
    • Thread Group 1
      • Sampler BSH : wait for latch
    • Thread Group 2
      • Sampler BSH : count down latch

In this case, the PreProcessor is run before each thread initialization. I run X times the preprocess sample.

Correct test plan :

  • Test Plan
    • Set up Thread Group
      • Sampler BSH : init latch
    • Thread Group 1
      • Sampler BSH : wait for latch
    • Thread Group 2
      • Sampler BSH : count down latch

The setup Thread Group is run before the others thread groups (these ones are parallel until you say not to do)

Fil RSS des articles de ce mot clé