0
votes

I have to test a Post, Get, Delete API in Jmeter. It should happen in sequential. I have added all the 3 APIs into a single thread group. It was running in sequential order. I read a lot of documents, though it ran the sampler in sequential, when the thread count increases, there is no guarantee of order.

So, I created a three thread groups and enabled sequential run. There is no problem with Post and Get. When Delete API invokes it will delete the entry. When the delete sampler runs again, the record won't be there in DB. Delete should happen after Post.

How to address this problem? or adding inside a single thread group is fine?

Suppose I have 3 thread groups, first one is for POST, next one is for Get, last one is for Delete. I want to run each thread group exactly once. Once it executed, next thread group should start. Once the delete thread group ran, it should invoke the first thread group again. Like that, I want to run the loop for n number of times with n number of threads. Can I do that?

3

3 Answers

0
votes

The order is guaranteed, each thread (virtual user) executes Samplers upside down, you can add __threadNum() function and ${__jm__Thread Group__idx} pre-defined variable to track this

enter image description here

If you have requests under different Thread Groups - the order is not guaranteed, you will have to implement waiting functionality using i.e. Inter-Thread Communication Plugin yourself

0
votes

Within a thread group Samplers always run in a sequence. When you say that thread count increases, there is no guarantee of order what is exactly happening?

EDITED ANSWER BELOW enter image description here You are getting confused with multi thread (multi user) scenario. if you have more than 1 thread, every thread will execute the samples in the exact same sequence as given by you.

When you move to multi user scenarios; no two threads will execute in sync. This is also not possible technically as your database executed DML queries in sequence to avoid bad data and race conditions. Also, your server load will cause one thread GET operation to run slow then other thread POST operation. If you see the picture I attached with this edit, then you could realize what Dmitri and me are trying to tell.

Carefully observe the red blocks in screenshot attached by Dmitri. It is the same thread and all the operations are happening in sequence with multiple iterations.

0
votes

enter image description here

Read the comments from Rahul and Dmitri. If you have unique data for each thread group, you won't face any issues. If you have a limited number of inputs, try this solution. Critical section controller enforces the request to be executed by a single thread and the named lock will be taken.

To know more, Read this article