Search code examples
jmeterperformance-testingload-testing

JMeter does not follow request sequence, while executing script for multiple threads


I have prepared a JMeter script.

It has multiple requests. I fetch data from the response and use it as a parameter for the next request.

i.e.

  1. Request 1: Add Item
  2. Request 2: Edit Item [Item ID fetched from 1st request's response]
  3. Request 3: Delete Item [Item ID fetched from 1st request's response]

It works perfectly fine with a single thread. But, when I run the script for multiple threads, it is not working properly.

i.e.

  1. Request 1: Add Item (Thread 1)
  2. Request 2: Edit Item [Item ID fetched from 1st request's response] (Thread 1)
  3. Request 3: Edit Item [Item ID fetched from 1st request's response] (Thread 2)
  4. Request 4: Delete Item [Item ID fetched from 1st request's response] (Thread 1)
  5. Request 5: Delete Item [Item ID fetched from 1st request's response] (Thread 2)
  6. Request 6: Add Item (Thread 2)

In Request 5 it tries to delete already deleted item, hence failing. This runs in a very random way.

Please help.


Solution

  • It is working as expected. If you edit and delete the same item with different threads the first thread which comes to executing delete request will remove it and others will fail.

    It should go like this:

    1. Request 1: Add Item (Thread 1)
    2. Request 2: Add Item (Thread 2)
    3. Request 2: Edit Item [Item ID fetched from 1st request's response] (Thread 1)
    4. Request 3: Edit Item [Item ID fetched from 2nd request's response] (Thread 2)

    You can use __threadNum() function as i.e. postfix to uniquely address ID of the item created by a specific thread. For instance ID_1 variable will hold ID of the item, created by 1st thread, ID_2 - by 2nd thread, etc.

    You can refer variables using dynamic thread numbers using __V() function like:

    ${__V(ID_${__threadNum})}
    

    See Functions and Variables chapter of JMeter's User Manual and How to Use JMeter Functions posts series for more information on above and others JMeter functions.