Pandarian Ld
Pandarian Ld

Reputation: 767

Use JMeter to simulate receiving websocket broadcasts similar to okhttp3

I'm working on Android application and we use okhttp3 to open websocket connection to our backend. There are 2 main websocket:

  1. request-response mechanism for requesting information from backend.
  2. subscribe mechanism for receiving broadcast or notify from backend.

The problem is I cannot simulate subscribe flow in JMeter and Postman. The flow in Android is

  1. Login to the system using username-password through REST API, the server return token
  2. Create new OKHttp Websocket Client
  3. Send WebSocket Request to backend, tell them which message I want to subscribe.
  4. Wait for the message from the backend.

Then I create test plan as follows:

  1. [CSV Data Set Config username] Get username-password from .csv file
  2. [HTTP Login Request] Calling REST API to login
  3. [WebSocket Open Info] Open WebSocket Connection
  4. [WsSubscribeReq] Send a message to backend telling the message code I want to subscribe (same format as the message used in Android).
  5. [WebSocket Single Read Broadcast] Loop wait for incoming message.

enter image description here

I was running my Android application at the same time as I running JMeter, Android got the broadcast message but JMeter did not get any message.

How can I make this works?

Upvotes: 0

Views: 39

Answers (1)

Ivan G
Ivan G

Reputation: 2857

In its current form the question cannot be comprehensively answered so I can only give you a generic hint: given you send the same request you should be getting the same response.

  1. Compare the requests originating from the Android application and JMeter using a sniffer tool.
  2. Amend JMeter configuration so it would send exactly the same requests like Android application does
  3. You should see the same behaviour

Pay attention to literally everything, URL query string, headers, payload which can contain non-printing characters

It also worth enabling JMeter debug logging for the plugin by adding the next line to log4j2.xml file:

<Logger name="eu.luminis" level="debug" />

and checking server-side logs for any suspicious entries.

Upvotes: 0

Related Questions