How do I manage in Jmeter, the expiration time of a token, so that it does not affect the continuity of execution of the other requests?
Normally when you're getting the token you're getting its TTL as well which could be extracted into a JMeter Variable
So you have 2 options:
Either periodically send the request for the token refresh in another Thread Group (token TTL minus some reasonable number of seconds), the pause between "refreshes" can be introduced using Constant Timer or Flow Control Action sampler
Or make the token refresh a part of the main Thread Group.
When you create/refresh the token you can get the current timestamp using __time() function and store it into a JMeter Variable
Then the current time can be compared to the token refresh timestamp in the If Controller so you will be able to run the refresh request before the current token expires
Related
I have generated the auth token in setup threadgroup and have passed the auth token to other threadgroups using setProperty and property.But the token expiry time is 30mins. How do I setup the scenario in jmeter so that this can be handled
Convert setUp Thread Group to "normal" Thread Group
Add a Flow Control Action sampler which will introduce delay of, say, 29 minutes and add more loops to the Thread Group
This way each 29 minutes JMeter will request for the new token and update the property holding the token with the new value.
Also be aware of Inter-Thread Communication Plugin, this way you will not only be able to pass objects between different threads but implement custom logic like the other thread will wait until the object is present in the FIFO queue.
I am working on setting up a way to do a performance test for the rest API's using Jmeter which includes token expiry for every three minutes.
1.)Currently, I created two thread groups one for making a call to get "access_token" and setting into the property using Bean shell assertion setProperty, to be used in other thread Groups.
2.)I could see Second thread group can access the value set in the first step.
But my goal is to execute the first thread group every 2min 30 seconds continuously so that the second thread group can get the new token every 2 min 30 seconds.
I tried a constant timer, but didn't seem to work is there any way to do this or any other timer to use to achieve this token refresh?
Thanks in advance
The Constant Timer should work, but be aware that it creates a delay before each Sampler it it's scope so it might be the case your setting it up wrong, you can use i.e. a Dummy Sampler and put the Constant Timer as a child of the Dummy Sampler, this way your HTTP Request to get token will be executed, followed by the delay defined in the Constant Timer, followed by the Dummy Sampler, et.c
Example setup:
You might find Flow Control Action sampler easier to use
Also be aware that starting from JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting. Moreover it's not required to write any code, you can go either for __setProperty() and __P() functions combination or for Inter-Thread Communication Plugin
There is an LoginAPI which will generate a bearer token and same token is used as part of header in subsequent apis(API-1, API-2, API-3).
LoginAPI is called under SetupThreadGroup, which will write the tokens to file
OtherAPIs(API-1,API-2,API-3 are called in a seperate thread group which will read tokens and use it in API's)
Currently, token expiration time is 30 minutes.
If we execute load test for 1 hour then post 30 minutes test, all the request gets failed with authentication issue(As tokens have expired)
Can any one suggest a solution to handle re-generation of tokens when expired and re-use the same in load test.
This way, i can run test for a longer duration.
Switch from setUp Thread Group for "LoginAPI" to normal Thread Group and configure it to run either desired number of iterations or forever
Add Flow Control Action sampler to the end of the "LoginAPI" thread group and configure it to "sleep" for i.e. 25 minutes
This way first thread group will execute the Login generating or refreshing the token each 25 minutes so "Other" thread group should be safe
If you need to pass the token from LoginAPI to OtherAPIs you can use either __setProperty() and __P() functions combination or Inter-Thread Communication Plugin
I have sampler which generates token, this token need to be passed to APIs as header. I want to execute token generator sampler every 10 minutes as the token will expire after 10 minutes. How can I handle this in JMeter?
The easiest solution would be creating a separate Thread Group with 1 virtual user and 1 HTTP Request sampler which will be refreshing the token.
In order to make it happen each 10 minutes add Flow Control Action sampler and configure it to introduce delay of 600000 milliseconds
To pass the token to other Thread Group(s) you can convert the JMeter Variable into a JMeter Property via __setProperty() function and read it back using __P() function. If you need a token per thread (virtual user) consider using __threadNum() function (in this case the number of threads must be equal to the total number of virtual users)
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
I have created a thread with three steps to:
Access token request: it generates a token to be used in step three. This token is stored in a property
${__setProperty(accessToken,${accessToken})}
Logon Get request to hit a url
Logon Post request, pass some data to the url and I have set the Authorisation header using the Bearer + accessToken (the one generated in first step.
Running a single thread it works, perfect; but when I increase the number of threads, the 3 steps are not running in sequence, maybe I have some Access token before the first Logon Post and I see the token this one is using is not the token generated in the first step, it is the last one generated.
If I set a rump time longer of the total execution time it works, but then I cannot run several threads on parallel.
How can I configure the script to run the threads using the correspondent token generated in step 1 in each Post? How can I different properties or variables to store the token of every thread and use them?
Thanks.
Your issue is that you are mixing Variables and Properties.
In summary, as per functions reference:
Variables are per Thread
Properties are shared accross Threads
So don't use setProperty, just use ${accessToken}
Use property only when you want to effect all threads. Otherwise you can save variables in other variable as in User_Parameters where you put new variable name the value can be a different variable as ${accessToken}
filling in the Variable name in the 'Name:' column. To add a new value to the series, click the 'Add User' button and fill in the desired value in the newly added column.
Values can be accessed in any test component in the same thread group, using the function syntax: ${variable}.