Search code examples
multithreadingjmeterjmx

How to get Elapsed time from Jmeter


I need to generate a token for every 2 hours (the expiration of token is 2 hours). How to get the time so that for every 2 hours I need to regenerate the token. Consider I need to perform a load test of 8 hours and every 2 hours the token should automatically generate it.

Is there any controller available in Jmeter for the above process. Any help will be much appreciated !!

Note: My test plan contains 2 thread group where first is to create the token and second is to perform the load test. As of now I am redirecting to generate token when previous request fails.


Solution

  • I would configure 1st thread group to generate a token each 2 hours, i.e.

    1. Set Loop Count to -1 or tick Forever
    2. Once you have your token generated use __setProperty() function to store it into a JMeter Property with any meaningful name, i.e. token
    3. Add Test Action sampler and configure it to Pause for 7200000 milliseconds
    4. In the second Thread Group you can access the token value using __P() function like ${__P(token)}

    More information: Knit One Pearl Two: How to Use Variables in Different Thread Groups

    JMeter Properties are global for the whole JVM therefore once the value is set in 1st thread group it will be immediately updated in 2nd thread group.