Scenario Outline
Test sends a REST API request to activate a game. Website receives a socket.io event and displays an alert on the browser.
Question
Since I don't know when the event will be sent, do I need to run a WebSocket Sampler, or perhaps a WebSocket Single-Read Sampler, in a loop, until I get the matching message? So far in my attempts, I can connect to the event server and get message, but they are empty frames or messages are entirely different from the below.
I expect a message like this, which I am able to verify manually using the browser debugger.
{
"locationId": 110,
"name": "GAME_STARTED", <---------------------
"payload": {
"id": 146418,
"boxId": 2002,
"userId": 419,
"createdAt": "2022-02-17T09:10:16",
"lastModifiedAt": "2022-02-17T09:10:22.189",
"completedAt": "2022-02-17T09:10:22.07",
"activationMethod": "TAG",
"nfcTagId": "123423423412342134",
"gameCount": 1,
"app": false
}
}
Alternatively, would this work?
thread A:
open socket
while (true):
read socket
if message ~ 'GAME_STARTED':
break
thread B:
send HTTP REST API request # triggers event to be sent
Here are the parameters used to connect and where I specify the response pattern, which needs wildcards or a JSON expression.
CodePudding user response:
You can consider using WebSocket Text Frame Filter
If you add the filter configured like above it will remove all the frames which don't contain GAME_STARTED
text so the WebSocket Single Read sampler will not "see" them, this way you can just have one sampler without any loops or other logic.
More information:
- Smart close with filter sample example test plan
- JMeter WebSocket Samplers - A Practical Guide