I'm developing a JMeter script for an ajax dashboard. The user logs in, navigates to a repository, clicks on the dashboard link, waits for the dashboard to display, and then logs out.
The dashboard has five dashlets. I've come to a point in the script where there are five pairs of samplers, one for each dashlet. The first sampler in each pair has a POST REST request with with ajax in the body. There is a regular expression extractor that extracts an id from the body of the response. This id is added to the URL in the second sampler of the pair, which also has a POST REST request with ajax in the body.
When there are one or two pairs of these samplers the script works 100% of the time, executing the samplers returning HTTP 200 responses and correctly substituting the id extracted from the first sampler in each pair, then logging out in the final sampler (exit.html). When the third pair of samplers are added I get the SocketException about once every 10-15 executions. With four pairs enabled it happens much more frequently, and with the fifth pair enabled it happens 100% of the time.
The odd thing is the SocketException occurs in the logout sampler, no other sampler. Also, if the logout sampler is disabled the socket exception never occurs, it works 100% of the time.
Here's the full stack trace:
java.net.SocketException: Socket closed
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1676)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1674)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1672)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.readResponse(HTTPJavaImpl.java:258)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:514)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.followRedirects(HTTPSamplerBase.java:1486)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.resultProcessing(HTTPSamplerBase.java:1561)
at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.resultProcessing(HTTPAbstractImpl.java:338)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:588)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1141)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1130)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:431)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:258)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:689)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1324)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2691)
at java.net.URLConnection.getHeaderFieldLong(URLConnection.java:639)
at java.net.URLConnection.getContentLengthLong(URLConnection.java:511)
at java.net.URLConnection.getContentLength(URLConnection.java:495)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.readResponse(HTTPJavaImpl.java:224)
... 12 more
I would appreciate any help debugging this
I believe that you're getting Socket Closed error due to changes to HTTP Requests default settings changes including
disabling failing requests
disabling stale check
See Connection Reset since JMeter 2.10 ? wiki page for more detailed explanation and options on how to bypass it if you're absolutely sure that the problem is not with your web server.
Also, sending individual HTTP Requests isn't very correct approach for testing AJAX applications as AJAX assumes kicking off extra requests within the bounds of the same parent thread.Current JMeter implementation doesn't allow overriding parent Thread Group limitation so it isn't possible to spawn more than one request at a time using one thread.
Check out How to Load Test AJAX/XHR Enabled Sites With JMeter guide for options on how to properly test AJAX applications.
Related
During manual run on reaching the Home screen, the page keeps loading and the API calls timeout with 504 error(Received the same error during Jmeter execution)
But if the same page(Home screen) is refreshed three times manually, all the previously timed out APIs load successfully (status:200).
But I'm unable to identify how to refresh the page using Jmeter. Any help on this? Thanks!
I tried adding JSR223 preprocessor with the following Javascript -
load("API-url") in the script section but it doesn't seems to work.
As per JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
So in order to "refresh" the page you need to send the same HTTP Request to it using HTTP Request Sampler. If you want to send the same request more than once it makes sense to put in under the Loop Controller
Also given the above quote from JMeter documentation if loading the page triggers some AJAX requests to the API - JMeter won't execute these requests automatically, you will need to create a separate HTTP Request sampler per API request. Also real browsers execute AJAX requests in parallel so if there is more than 1 API request - you need to put them under the Parallel Controller
Here is the socket message I see in the browser debugger console:
More illustrative, perhaps:
I call an API operation that triggers this message over a socket.
What I Tried
To preclude inaccuracies, I started 2 instances of JMeter.
REST API call.
Revised version of the GitHub JMeter example of sockets.io, in which I just call a WebSocket Sampler repeatedly on wss://events.dev.myserver.com:443/socket.io/?EIO=4&transport=websocket.
I kicked off (2).
While that was running, I kicked off (1).
Expected
Eventually, (1) should show me a sampler in the View Results Tree with the message in the screenshot ("42" - GAME_STARTED)
Actual
The only messages I see look like this:
This is really all I want to do: run the appropriate sampler, a sufficient time after making the API call, to get the message.
Update
We succeeded in finding the message using python-socketio:
sio.connect("https://events.dev.server.com", transports='websocket',
headers={'Sec-WebSocket-Extensions: permessage-deflate', 'Sec-Fetch-Dest: websocket',
'Sec-Fetch-Mode: websocket',
'Cookie: ABCSESSIONDEV=NTI3MzkwNWUtMTJmNS00Y2U0LTk1NGUtMjQ2Mzk5OTYxZWE0'})
And here is the output:
Received packet MESSAGE data 2["message","{\"locationId\":110,\"name\":\"GAME_STARTED\",\"payload\":{\"id\":146724,\"boxId\":2002,\"userId\":419,\"createdAt\":\"2022-03-02T14:35:31\",\"lastModifiedAt\":\"2022-03-02T14:35:36.752\",\"completedAt\":\"2022-03-02T14:35:36.621\",\"activationMethod\":\"TAG\",\"nfcTagId\":\"xxxxxx\",\"gameCount\":1,\"app\":false}}"]
I would like to use the websocket plugin to do this in JMeter now.
tried adding Cookie to WebSocket call - only sids, no messages.
tried adding Cookie to an HTTPS request (like the above code) - 400, bad request.
Take a look at other fields of the HTTP Request, in particular HTTP Headers, most probably your JMeter request is missing some essential information.
My expectation is that in order to "start the game" (whatever it means) you need to open the page in the browser, authorize somehow, follow the steps of the protocol upgrade mechanism, etc. to wit exactly mimic what real browser does, all the request sequence which is prior to starting the game.
You might need to correlate dynamic parameters, add HTTP Header Manager, add HTTP Cookie Manager, etc.
I am using the Jmeter WebSocket Sampler. I have successfully connected to the websocket, and can send a json request. It is a chat bot, and I will be validating it's response.
However, I have observed in websocket log, the websocket responds to the json request with a short confirmation response before the actual response.
for example, the first response is {"event":joingame,} where the response is {"event":"game"}. I don't really need this information.
Only then is the real response sent (as I observed in webscoket log)
I have tried the general Websocket Sampler.
The websocket responses come in "frames", each having a JSON response, my samplers are closing right after the first frame.
You might want to switch to the WebSocket Samplers by Peter Doornbosch which can be installed using JMeter Plugins Manager
This way you will be able to establish a connection first:
and then continue reading the frames re-using the connection unless you find the frame with the content you're looking for:
It makes sense to use JSON Extractor and While Controller in order to continue reading until the anticipated text appears in the response.
More information: JMeter WebSocket Samplers - A Practical Guide
I'm trying to do JMeter script for an application with Signalr protocol.
I'm able to identify connection-token, bearer-token, connection-id and co relate with request using long polling transport and receive message, but after third polling I could not receive the correct response, i'm getting response but not the expected and full response.
Could you please help me what could be the issue here?
I'm afraid no one will be able to help without seeing at least:
Anticipated response
Actual response
Reference requests sequence from i.e. real browser captured with a sniffer tool like Wireshark or Fiddler
The same as point 3 but for JMeter instead of the real browser.
Basically you need to execute points 3 and 4 and compare the generated network requests - they must be the same apart from the dynamic parameters (tokens, connection-id, etc.). Given requests are the same - you should be getting the same responses.
Another option is using While Controller in order to continue polling unless response matches your expectation.
I have read and tried the solutions shared in the previous posts for this error but nothing helped me to fix this. Kindly help.
I am making a HTTPS API call. A very simple call which accepts a 2 KB JSON message via POST method and sends a one word acknowledgement. It works perfectly fine in Postman tool. In JMeter, no. of threads (users) is kept as 25. It works perfectly fine one time with all 25 success response and at times getting few failure response as
Response code: Non HTTP response code: java.net.SocketException
Response message: Non HTTP response message: Unexpected end of file from server
No consistency at all. I have also tried with both enabling and disabling "use keepalive" checkbox. Both giving me all success one time ; few/all failure at another time with the above error. Please help. Thank you.
Below are the JMeter settings:
HTTP Header Manager : Content-Type - application/json
HTTPRequest sampler : protocol - HTTPS
Server Name or IP : project server name
Method : POST
PATH : The required path with https authentication details passed as parameters
IMPLEMENTATION : Set to JAVA (HTTPCLIENT4 was giving me “443 failed to respond” error)
Add header
Connection Keep-Alive
Both errors (Java implementation and Apache HTTPClient4 implementation), are essentially saying the same thing: The server closed the connection, without providing any response. I think there could be the following reasons:
Authentication problem. If server side checks authentication before processing a request (e.g. using Spring), it may be rejecting your request, it may be not bothering with any response if authentication is not considered correct.
Request Issue. Some less noticeable properties of the request you send via Jmeter are different from what you send in Postman. It could be some minor thing with formatting, or some headers server expects. Some of such inconsistencies can also cause Load Balancer (if you use one) to reject request before it's delivered to the server.
Certificate issues. Since you are using HTTPS, you need to make sure your certificate is setup correctly on JMeter side.
So I suggest:
Review server logs and see if your request makes it to the server. If yes, you might be able to see how it was rejected. If not, you need to trace back and see who rejected it (LB, authentication, etc)
Compare headers and body sent by JMeter vs Postman line to line (use TCPDump for example to obtain it).