Getting 401 Unauthorized error when threads in JMeter increase - jmeter

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.

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

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.

Why is Parse.Cloud.httpRequest failing non-deterministically on a cloud method?

I am doing a method where I am using 2 Parse.Cloud.httpRequest calls, with one being inside of the other. However, this method seem to fail with an alarming frequency. Like 1 in 5 tries, each time the error is:
Request failed with response code 500
{"uuid":"bc75e304-8964-30f9-c9d5-92fabf02f624","status":500,"error":{"code":-1,"error":"Request timed out"},"headers":{},"text":"{\"code\":124,\"error\":\"Request timed out\"}","cookies":{}}
I looked up code 124, and it corresponds to
Timeout 124 Error code indicating that the request timed out on the server. Typically this indicates that the request is too expensive to run.
I am only running a couple REST requests per minute and the run of the method does not exceed 3 seconds. I checked the same calls via REST and there is never any problems.
What's the cause for this problem and can I fix it by upgrading my parse account?

jmeter response code 204 and can't get content

I am doing a websocket stress test through jmeter2.9.
When I send a request and response with a "light" json. the result is ok.
But when the response json contains a base64 png(about 360kb) . jmeter return code 204 No content (probably timeout).
Is my jmeter need some config here, or something else wrong.
If someone know something about this please teach me.
complete info:
Thread Name: threadgroup 1-1
Sample Start: 2013-07-17 15:36:06 CST
Load time: 20000
Latency: 0
Size in bytes: 0
Headers size in bytes: 0
Body size in bytes: 0
Sample Count: 1
Error Count: 1
Response code: 204
Response message: No content (probably timeout).
Response headers:
SampleResult fields:
ContentType:
DataEncoding:
Check if you are using Cache manager, there seems to be a (bug) in Jmeter that sets the response code to HTTP Code '204' ("No Response") while, there is no outgoing request, the information is retrieved from the Cache, try disabling cache manager and lets see if you can reproduce it then.
This could be because of the unhandled exception, response being larger than the maximum message size specified in the plugin code, etc. The exception which you see will be thrown if no response has been received from the server after predefined timeout.
Here is another WebSocket plugin for JMeter which might work for you
Link: https://github.com/maciejzaleski/JMeter
Features:
Supports HTTS/HTTPS (ws/wss) version of the WebSocket protocol
Option to ignore SSL certificate errors
Streaming allows for a single connection to remain open for the duration of the test
Response has to match predefined regular expression
Response timeout
Response message back log (build the Sampler response from multiple server messages)
Connection could be closed if server sends a mesage matching predefined regular expression

Resources