Reputation: 25
I am running my load tests in jmeter. I have login service and a serviceX which is to be tested. I want Authtoken from login service to run serviceX. Token expires every minute. Currently I am having login service in the same thread group and running as much as serviceX. I dont want to continue this. I want to run login service once in every minute in single thread and pass the token to serviceX and ServiceX runs the defined number of threads and time. how to achieve this?
Upvotes: 0
Views: 2303
Reputation: 168002
If you use only one token across all threads (virtual users) it makes sense to add another Thread Group with 1 thread and infinite number of loops to your Test Plan and add a HTTP Request sampler to it along with the relevant Post-Processor to extract the token. Also add a Constant Timer to add pauses between requests, i.e. use 55000
milliseconds as the thread delay value.
Once you have the token you can convert it into a JMeter Property via __setProperty() function
In your "main" Thread Group you can read the current token value using __P() function
Upvotes: 0
Reputation: 2978
Use Once Only Controller to achieve this. This controller executes the request inside it only once per thread
and passes over any other requests under it during further iterations through the test plan.
So, you can put your login service inside the Once Only Controller and serviceX
outside of the controller. You have to configure your Thread Group accordingly for the iterations or you can wrap up your serviceX
under Loop Controller.
Example:
Say, you want to login
your first thread only once and then wants to run serviceX
for 10 times, here is the below test plan sample:
Remember, as you want to log in once in a minute and once the only controller works on per thread, so you have to use rampup your thread groups accordingly. Suppose, there are 2 threads, and they will log in in a one-minute interval, then the Thread group configurations will be like:
Now, if you want to run your serviceX
for 5 times after the 1st thread login, put your serviceX
under the loop controller scope and the loop count value to 5
This is the results of this sample test plan:
Hope this helps!
Upvotes: 1