How to synchronize 2 requests (samplers) in JMeter - jmeter

I have test in jmeter that call get oauth token (Token request) and than call rest web service. Problem is that it call Token request to early and when It call web service, it fails becouse token is no longer valid. Can someone help me to fix it in the way, that Token request will be executed few seconds before web service call?
My test config in jmeter
Throughput Controller
Constant Throughput Timer

Normally you shouldn't do anything because each JMeter thread (virtual user) executes Samplers upside down and looking into your test plan I can see that the token request is before the authenticated request so it shouldn't be a problem (unless token life time is below 1 minute)
Whatever.
If you want to introduce a delay between 2 requests there are following options:
Add Flow Control Action Sampler before the 2nd request
Add a relevant JMeter Timer (i.e. Constant Timer) as a child of the 2nd request

Related

How to send some api call sequentially and some api calls parallely for the same user action

How to send some api call sequentially and some api calls parallely for the same user action .
You can make use of Parallel controller
I tried to simulate your scenario in this screenshot below
I added 2 Debug Samplers before Parallel controller and 2 after the controller. On the right hand side if you see Debug Sampler 3 and Debug Sampler 4 started at same time whereas others have a different start time indicating a sequential run.
For sending requests sequentially just add HTTP Request samplers, one per request and each JMeter thread (virtual user) will execute them upside down
For sending requests in parallel put the relevant HTTP Request samplers under the Parallel Controller

CSS/JQuery extractor is extracting default value in case of load test, for the random threads

Performing a login and update user test with multiple users.
I have created a CSV file with 200 username and passwords. Running 200 threads
Performing login and update user, with 200 users.
I am extracting the value of csrf token in a variable after the login request. Then, I am passing that csrf variable in the user update, post request.
Running the same request with 100 users, I am able to log in and update the user's details.
Running the same request with 200 users.
getting the connection timeout exception.
Some of the update user post requests are getting failed because csrf variable is extracting the default values of CSS/JQuery extractor. CSRF token actual value is not getting extracted to the variable.
I have also added Authorization, Cookie, Cache and Header Manager in my test plan.
The constant timer is also being used after login request.
I have set the value of timeouts to 120000 in the HTTP request defaults. Even if I am increasing the timeouts, getting the same exception.
Most probably your application under test simply gets overloaded therefore it cannot respond in a timely fashion.
With regards to CSS/JQuery extractor which is failing to get CSRF token - my expectation is that the token is not present in the response for failing samplers.
So I would recommend taking the following troubleshooting steps:
Completely remove Connect and Response timeouts in the HTTP Request Defaults so JMeter will wait for response forever.
Configure JMeter to save responses for failed samplers by adding the next 2 lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data.on_error=true
this way you will be able to see how does response look like for failing requests. See Results File Configuration User Manual chapter to learn what other metrics could be useful for your analysis.
Check your application and middleware (web/application/database server/load balancer logs)
Make sure to set up monitoring of baseline OS health metrics on the application under test side. You can do this using JMeter PerfMon Plugin
Just in case double check you're following JMeter Best Practices

Jmeter - Parallel execution of HTTP request after Login

Scenario
Navigating to a login page which generates session data key which will be used while entering the credentials for login
Entering credentials along with sessiondataKey(i.e. sessiondatakey is a entered as parameter in Jmeter Http Header )
Login mechanism provides authorization token
Once authorization token is extracted from response ,initialization request is triggered
As this a XHR enabled site - multiple requests are triggered all together at same time to API's once response from initialization service is received (Note - Here in every request authorization token which we got previously is sent as a part of Header)
Question - What should be My Test Plan structure in jmeter where I would like to login with 50 Users (Data referred from CSV datset) - Once Login - Initialization done then fire up all request together.
Just go for Parallel Controller, your test plan should look like:
Login
Parallel Controller
Request 1
Request 2
Request 3
etc.
So Request 1, Request 2, etc. will be executed at the same time, each with its own thread.
See How to Use the Parallel Controller in JMeter article for comprehensive information if needed.
You can install Parallel Controller using JMeter Plugins Manager

Running Jmeter for Https app with single user for multiple times through Loop controller

Attached is the snapI am trying to run jmeter for single user with value of 10 in loop controller , I first login into the app and then subsequently uses the CSRF token accordingly for future request .The login is always successful and generates CSRF token, But when i try to use CSRF token for future request , I get unauthorized HTTP 401 reponse code , when running with value 10 in loop controller for single user , the same works when i try to run single user with value 1 in loop controller , Any idea how to fix this? (Note :- All this is present in same thread Group)
Well-behaved JMeter test should be able to loop single user without any problem, most likely you have a problem with your test design or mismatch with the application under test behaviour. General recommendation would look like:
First of all switch to iterations on Thread Group level, JMeter configuration elements don't respect iterations originated from elsewhere as "iterations"
Add Debug Sampler and View Results Tree listener to your Test Plan
Run your test with 1 user and 2 loops
Inspect request and response details, identify missing/extra/different parameters and fix them. See How to Debug your Apache JMeter Script for more details on JMeter test troubleshooting techniques.
Blind shot: your test includes login request and the virtual user is already logged in therefore it doesn't require login on 2nd loop. In this case you have 2 options:
Put the logic which needs to be executed only 1 time under Once Only Controller
If you use HTTP Cookie Manager be aware that Clear cookies each iteration works only on Thread Group-level iterations

Need to send the web service request contentiously till get response using JMeter

My requirement is as follows:
I will be copying one test data file to one location. [My application will pick file, process it and will respond using web service]
So when I login to my application and go to that page, every 5 seconds web service request would be sent.
Above two, i can handle using JMeter. Now next is
Need to send the web service request contentiously [maybe each request in 5 seconds] till get response using JMeter
So how can I do this?
Please help. Thanks!
Something like:
While Controller with condition depending on the response
HTTP Request Sampler
Constant Timer to sleep for 5 seconds
Maybe a Post-Processor to set the While Controller's condition
See Using the While Controller in JMeter article for more details on implementing while loops in JMeter tests.

Resources