Jmeter - running multiple threads using different author token - jmeter

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}.

Related

How to update the array values from existing based on the condition and again pass same array with updated array element

We are using for each control to iterate an array based on matchNr count. First time My application is sending all reports call to server together , next time after 10 sec delay again my application sending the same reports calls which are not get completed in first time and so on.
Ex. suppose application is having 10 reports then first time 10 requests goes, then again same request goes by eliminating the completed one (this request count should be less or equal to earlier one)
Note:
Application is having different report count for each users. we can not put fix reports to all users.
Request is same here, only application is adding report name in the body part of the request.
We are trying to simulate chrome behavior with Jmeter during load test.
Array is having the total report count[image1]
request is same only parameter is getting change for each request[image2]
ForEach Controller doesn't execute its children "together"
We are not telepathic enough to guess how does you "array" look like and how exactly you want to "update" it
If you have JMeter Variables in form of:
foo_1=something
foo_2=something else
....
foo_matchNr=number of matches
and want to update the variables with some "new" values there are 2 options:
Set Variables Action sampler (can be installed using JMeter Plugins Manager)
Or any suitable JSR223 Test Element, any of them has vars shorthand for JMeterVariables class instance providing read/write capabilities for JMeter Variables in current thread's scope.

Handle oauth token in Jmeter

While running my load simulation in JMeter as follow, the oauth that I am generating from the system at the step one is override by a new one while I am in step 16(please refer the image attached), how to handle this in JMeter that until my all the transaction controller finished execution don't generate a new token. (Please refer the image attached and the description)
Description:
In step 1 I am generating the bearer token for my application and which is going to use for my entire iteration
While the iteration is running and reached step 16(till this it is hardly take 30 sec and marked 2) a new token generated for the user which I used in step 1.
Is there any condition I am missing because why it is creating a new token because it is not reached the entire journey or do I need to something else?
Here is how I am extracting my token
And here I am passing this in step 16,
This screenshot doesn't provide the full information as it's unclear how do you "generate bearer token" so I can only make some assumptions:
You're using a JMeter Property (which are "global") instead of JMeter Variable which are thread-local so when the other thread is generating a new token it overwrites the old value, make sure to use variables, not properties
Your "token generation" logic scope is incorrect and the Post-Processor which does the extraction is being applied to more than one request.
Due to a logic error or a copy paste issue you're overwriting the variable somewhere in step 15, use Debug Sampler to print the token value after each step, this way you will be able to localize the problem and find the problematic block in your script which causes the problem

Jmeter. How to pass a variable generated by each user in thread to second thread users?

Good day, guys!
What I attempting to do is perform a clean logout for all users after test stops running via duration restriction.
In my case, when user logs in, he gets unique session id parameter that makes it impossible to log with same user from different tab/browser/place, so I need to be sure that user is not blocked after my test completes.
Lets say I use 100 users for a test.
My test looks something like:
Login (get session id)
do stuff
do stuff
Logout (terminate session)
It works fine when I use a constant set of loops, but when I run test with duration, for example, 600 seconds, test stops in the middle after time runs out and my users are blocked until their sessions expire by timeout.
I tried to create a second thread which also contains 100 users and only a logout HTTP sampler, passed and used session id variable to it as described in article https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups but it seems that my second thread receives only a last session id value so it basically logs out 1 user 100 times, but I need to log out 100 users 1 time.
Does anyone now how to store multiple values of a variable and use them in correct order in other threads?
Not a programmer, just a manual tester with some extra responsibilities.
Thank you.
JMeter Variables are local to each thread, JMeter Properties are global for the whole JVM so if you're passing variables between thread groups make sure you add current thread number as a prefix (or postfix) for the generated property, something like:
In the first Thread Group define user-specific property using __setProperty() and __threadNum() functions combination:
${__setProperty(foo_${__threadNum},${YOUR_VARIABLE_HERE})}
In the second Thread Group get user-specific property using __P() and __threadNum() functions combination:
${__P(foo_${__threadNum},)}
Replace foo with the property name of your choice
Replace YOUR_VARIABLE_HERE with the name of the relevant JMeter Variable
Demo:
See Apache JMeter Functions - An Introduction to get familiarized with JMeter Functions concept.

Apache Jmeter - need thread scope variables

I am trying to run websocket load testing and find I need access to variables defined at thread scope.
Specifically, I need to randomly generate a UUID to be used as a pseudo-user ID. Our API requires this to be passed as a parameter with each request :
send auth request with the UUID
- this will create a user account keyed on system information
wait for response
loop sending sync/initialize with UUID
The UUID is the app id. I can randomize that easily with a User Defined Variable via the UUID function, however, user defined variables are apparently calculated once at the start of the test whereas I need them to be generated at thread group scope. Is there a way to do that? If now, how can I achieve this?
In other words, I need a randomly generated UUID for each thread (acting as a user) which is accessible to each sampler in the thread group.
Thanks in advance!
You can use a Beanshell preprocessor for the very first sampler which needs this UUID as shown below.
vars.put("uuid", "${__UUID}");
All other samplers in the thread group for the user/thread will have the same UUID and it can be accessed by using ${uuid}.
I do faced this issue during the load test, the solution is
Use epoch time (ms) and append UUI value. This is the solution because epoch time never be same , if two transactions are issued at the same time, UUI changes every time. So whenever you run the test, these values should be unique.Below is the code for reference
epoch Time:${__javaScript(Math.round(new Date().getTime()))}
UUID: ${__BeanShell(UUID.randomUUID().toString())}
Combination is :${__javaScript(Math.round(new Date().getTime()))}_${__BeanShell(UUID.randomUUID().toString())}

JMeter - Why is my variable being re-evaluated midway through my test?

I posted this question originally in a much more complicated way, but I've reproduced the issue more simply now so I'm extensively editing my post.
I have a simple Test Plan to exercise an API.
The first thing it does is create a session with a simple HTTP POST. We then extract the session ID from the response using the JSON Path Extractor plugin:
This reads the newly created session's ID into a variable called id_JSON, and subsequent PUT requests use the session ID in their path, i.e. /api/sessions/${id_JSON}/account.
This generally works well, but I have noticed that intermittently, id_JSON will suddenly have the default value NOT_FOUND. Samples will fail and when I look at the request, I can see that it was trying to hit /api/sessions/NOT_FOUND/account instead of a valid ID. What's really confusing me right now is that this will happen after requests have already successfully referenced ${id_JSON} and generated a valid path. It seems like this should be impossible, unless the value of id_JSON was being dynamically checked or looked up repeatedly - otherwise how is it coming up with a different value from one request to the next?
It seems that if any Sample fails, for any reason, subsequent requests in the same thread iteration all fail with id_JSON having the default value NOT_FOUND.
Do I need to declare or manage the variable id_JSON in any special way to ensure that it will get the value of the session ID and retain it throughout the thread iteration, until the next iteration overwrites it with the next session ID?
The Extractor is a Post Processor, meaning it is applied after each sampler. So in you case it will run on the First Get and the 4 Puts.
So what you are noticing is absolutely regular, and if a Sampler fails, the extractor will fail to extract the ID and put NOT_FOUND in value.
If you are sure it does not change, then just put the Post Processor as a child of the first HTTP Request called "Create Session", it will then only run for it and the variable will not change anymore.
You can read more on this at:
http://jmeter.apache.org/usermanual/test_plan.html#scoping_rules
"Go to next loop iteration" operates on Thread Group level.
Using any nested loop controllers doesn't increment global iteration counter. You can test it with either:
${__BeanShell(vars.getIteration();)} function - if you use vanilla JMeter
iterationNum function - if you use JMeter Plugins
So if you move your "looping" on Thread Group level and remove nester Loop Controller(s) (or set their loop count to 1) your approach should work as you expect it to do.

Resources