JMeter - Execute HTTP Request until Response Headers matches - jmeter

I'm new with JMeter and I'm working with a script for checking the cache, the scenario was to:
do a GET request
verify that it has been cached
do a DELETE request
verify that the cache has been deleted
However since there are three instances in the environment I'm working on my script is having intermittent failures because of the different x-internal-service-host being returned.
My test results looks like this:
do a GET request (x-internal-service-host returned is
c3c8021a51a9:8080 - PASS)
verify that it has been cached
(x-internal-service-host returned is 4eb7ac9d4a76:8080 - FAILED
because the call made was for c3c8021a51a9:8080)
do a DELETE
request (x-internal-service-host returned
is c3c8021a51a9:8080 - PASS)
verify that the cache has been deleted
(request x-internal-service-host returned is c3c8021a51a9:8080 -
FAILED because the delete was made for 4eb7ac9d4a76:8080)
I'm thinking of extracting the Response Header x-internal-service-host in step 1 but I'm not sure how to proceed once extracted, is it possible to send a GET request until the Response Header extracted matches the Response Header result for steps 2 to 4 or is there a better way to do this?

Related

My test works in Jmeter but not in Azure Load Testing

I've defined a test on Jmeter which works correctly on Jmeter on my pc, but it doesn't work when I run it Azure Load Testing.
My test is very simple: it performs a POST request towards Azure AD (https://login.microsoftonline.com/TenantID/oauth2/token?api-version=1.0) with a body like the following one in order to retrieve a token:
"grant_type" = "client_credentials";
"resource" = "$resource";
"client_id" = "$APPID";
"client_secret" = "$ClientSecret"
JMeter parameters for the POST call
When I perform the call from my PC, it works and I'm then able to use the token to perform some other calls (not relevant here).
When I perform this single call on Azure Load Testing with my jmx file, the calls fails with a 400 (Bad request), as if my request was malformed.
When I download the results of the test, I get the following csv:
timeStamp elapsed label responseCode responseMessage threadName dataType success failureMessage bytes sentBytes grpThreads allThreads URL Latency IdleTime Connect
1.67602E+12 147 Get token 400 Bad Request 172.18.19.5-Setup Authentication 1-1 text FALSE 925 1119 1 1 https://login.microsoft.com/*tenantID*/oauth2/v2.0/token 144 0 107
where tenantID reflects the actual tenant ID.
In order to troubleshoot it, I've tried to replace the values of the tenand id with the values of client id, scope and secret and they show up correctly in the log file when I execute the test.
Also, in my AAD logs I don't see my login attempts, probably because of the 400 - Bad request code, as if my request was somehow malformed, so it doesn't get logged.
I've no idea how I could troubleshoot this further (e.g. can I somehow trace the parameters of the POST call Azure Load Testing is doing?). Any suggestions?
thanks for your help,
Marco

Rerun getToken(authorization) requests only on expiry - Jmeter

My testplan is as follows:
get token: requests to get access token
Setting a user defined variable to get the tokenGeneratedTime, let's say tokenGeneratedTime to ${__time(,)}
Check if token is expired(if controller) - {__jexl3((${__time(,)} - ${tokenGenerationTime}) > 3599000)}
if true, goes to get token sampler
if false, goes to subsequent requests
Some https requests
So if I run this test plan for the first time(only 1 iteration), request to get token is fired, the condition would be evaluated as false and the subsequent requests are fired. All is well and good. But as you can see, if I run the test plan again immediately(not iterating) for the second time, the get token(authorization) requests are fired again, which is not needed. I need to call the get token requests, only on expiry.
I'm thinking of setting a variable to false, if the token is not expired and putting the get token requests under an if controller. But how do I set a variable in if controller?
If you have any other ways of achieving this, please do suggest.
TIA
Use a flag to check the token expiry. e.g. isTokenExpired
Define the variable in the User Defiled Variables section and set the value to true. This will ensure token request is fired for the first time.
Add an IF Controller to the token request and check the condition ${tokenExpired}. Set the flag to false when a token is created successfully. vars.put("tokenExpired","false")
Add a JSR223 Postprocessor to the top level and check the response code 401 for the token expiry response. If the token is expired, set the flag isTokenExpired to true and redirect the thread to the next iteration immediately ctx.setTestLogicalAction(org.apache.jmeter.threads.JMeterContext.TestLogicalAction.START_NEXT_ITERATION_OF_THREAD .
String responseCode=prev.getResponseCode()
if (responseCode.equals("401")) {
log.info("Token is expired ")
vars.put("tokenExpired","true")
ctx.setTestLogicalAction(org.apache.jmeter.threads.JMeterContext.TestLogicalAction.START_NEXT_ITERATION_OF_THREAD )
}
if I run the test plan again immediately(not iterating)
If you run the test plan 2nd time it means that your tokenGenerationTime variable gets a new value of the current timestamp equal to the start time of 2nd execution.
If you want to be able to run your test plan 2nd time within 1 hour without firing the token generation request you can consider writing the tokenGenerationTime into a file using i.e. __StringToFile() function and read it from the file on 2nd and other test executions using __FileToString() function or if your logic is more complex you can go for __groovy() function and implement whatever you want there
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Value cannot be null: Parameter: Source error received from JMeter

I have been receiving this error message on particular request - "Value cannot be null. Parameter name: source".
My Scenario is that 1 user will be transacting 5 transaction (Search and Remit). I'm targeting to run 650 Users to 3250 Transaction. The problem is that one particular request which is getting details from the DB, some data is passed but mostly are the mentioned error message above.
I Have 2 CSV Config, 1 from Users, the 2nd is for the Data where the second csv is inside the Loop Controller.
Your application tells you that the request is not correct, it expects a value and you're failing to provide the value. Use Debug Sampler and View Results Tree listener combination to validate the values of the JMeter Variables which are being sent for successful and not successful requests, it might be a test data issue, for example an extra comma in the CSV file will make CSV Data Set config "think" that this is the delimiter for the next column.

Getting 401 Unauthorized error when threads in JMeter increase

I am running a JMeter script, where I get the Access Token which I use it for my HTTP Request Samplers (By using Bearer ${AccessToken} in Header Manager of each Request). My HTTP Requests are being categorized into multiple Simple Controllers.
There are 70 HTTP GET Requests and ONE Thread takes around 20 seconds to execute them all.
Now when my no. of threads increase, say 3 onwards, then I start getting 401 Errors
({
"statusCode": 401,
"error": "Unauthorized",
"message": "Bad token",
"attributes": {
"error": "Bad token"
}
})
for a few requests. But eventually 401 errors start getting high as no. of Threads increase, keeping Ramp Up time low. for eg: for 5 Requests Ramp Up time = 30 sec.
JMeter Script snapshot
I have checked, my Access Token call always return a different token which is used per new THREAD. so not sure where the issue is :(
So far I have not used any think times, maybe that is one of the issue, but not sure.
By looking at your http get response , The issue is caused most likely due to incorrect value of AccessToken.
Make sure you are passing correct AccessToken to get response.
IF you have a recorded script log, check where this access token originating from and make sure your regular expression extractor is extracting it correctly.
For more information on extracting variables and reusing it in the script you can read this article.

Jmeter- Under response data it is displaying error but under sampler result it is displaying 'Response message: OK'

I am having web application for which I have to test load for Monthly Report generation.
Ran thread group for 3 users and analyzing output using View Result Tree Listener, it is displaying '0|error|500||' and under Sampler Result it is displaying 'Response message: OK' for first two samples and for last sample it is displaying response data as 'Response too large to be displayed. Size: 5965092 > Max: 204800, Start of message: etc'
Can anybody tell what will be the issue, why it is displaying error under response data and response message as OK under Sampler Result.
Waiting for your response.
As long as JMeter receives something it can parse as HTTP, it won't call that an error.
You're going to want to add Response Assertions to the problem calls. Make sure that it doesn't contain an error depending what the response contains. Documentation can be found here.
When you get these errors after implementing Response Assertions, JMeter will refer to them as '200 errors,' which essentially means it was an error with a 200 response code.

Resources