0
votes

I have a test plan with several thread groups, each one performing different types of requests. The whole test plan is simulating our environment.

Each thread is using a special resource to send requests to the server, this resource is being built once (with a Once Only Controller) and stored in Jmeter Variables. Jmeter Variables are not shared among threads, so if I have 10 thread groups with 10 threads each one, I have 100 resources created.

I would like to disconnect this resource once each thread finish with its work.

Teardown thread groups cannot be used as the Jmeter variables are only seen by the thread that stored it.

The specific question is: how do I know when a thread has finished its work with Groovy?

2

2 Answers

0
votes

how do I know when a thread has finished its work with Groovy?

you cannot, however you can get current thread number and current iteration like:

if (ctx.getThreadNum() == 0 && vars.getIteration() == 10)
{
    //do what you need 
}

Another option is converting JMeter Variables to JMeter Properties (which are global for the whole JVM hence can be accessed from the different Thread Groups) and perform cleanup in the tearDown Thread Group like:

//assuming you have JMeter Variable called "foo"
props.put("foo", vars.get("foo"));

References:

0
votes

For your requirement, FIFO plugin seems to be a good choice. Please check here.

Basically, all the resources to be cleared are added to a queue - there is a separate thread group which could check this queue and clear the resources.