0
votes

enter image description hereI am new to Jmeter, and I am trying to achieve the following test plan in Jmeter 4.0.

I have 2 thread group.

  • First thread group will generate access token using Oauth 2.0 and the value of access token is set to a variable.
  • Second Thread group will use the access token generated from first thread group and process the HTTP request.

Token expiration time is 2 hours.

I want to schedule a 8 hours test in Jmeter. How to invoke first thread group to generate token for every 2 hours and to continue thread group 2.

Any help will be appreciated !!

1

1 Answers

1
votes
  1. Put If Controller after a sampler which could fail
  2. Use the following expression as the condition:

    ${__groovy(vars.get('JMeterThread.last_sample_ok').equals('false'),)}
    

    where:

    • JMeterThread.last_sample_ok is a pre-defined variable indicating whether previous sampler was successful or not
    • __groovy() function allows execution of arbitrary Groovy code, in above example it checks if the previous sampler is not successful.
  3. Put Module Controller as a child of the If Controller and point it to the 1st Thread Group

More information: Easily Write a GOTO Statement in JMeter


Update: use Test Fragments like:

  1. Add Test Fragment to your Test Plan and move the logic from Thread Group 1 there
  2. Add Module Controller to Thread Group 1 and reference the Test Fragment
  3. In the Module Controller from Thread Group 2 reference the same Test Fragment

    JMeter Test Fragmemts