Home > Software engineering >  How to await a WebSocket response in gatling without sending a message
How to await a WebSocket response in gatling without sending a message

Time:12-14

I'm working with WebSockets in Gatling and have a slight issue in that I get multiple responses with the same message and different values, but the original message is sent only once. The subsequent web socket responses are triggered by a graphql post.

Obviously .exec(ws("Web Socket Request").await(5) doesn't work so Im wondering how I would await and check the subsequent message?

You can see the requests in dev console here. Message with "id": "11" is sent and message with "id": "11" is received, then another one ("id": "11") is received after the graphql call.

enter image description here

So my code currently looks like this:

        .exec(graphQlRequests.onlineStatus(false))
        .exec(graphQlRequests.chatRooms())
        .exec(
            ws("Video Watch").sendText(subscriptionQueries.videoWatch()).await(5)
                .on(ws.checkTextMessage("Video Watch").check(jsonPath("\$..choices[0].id")
                    .saveAs("choice")))
        )
        .exec(ws("New Messages").sendText(subscriptionQueries.newMessages()))
        .pause(1)
        .exec(graphQlRequests.startVideo())
        .exec(graphQlRequests.chatRoom())
        .exec(graphQlRequests.onlineStatus(false))
        .exec(graphQlRequests.chatRoom())
        .exec(graphQlRequests.onlineStatus(true))
        .pause(9)
        .exec(graphQlRequests.onlineStatus(true))
        .pause(3)
        .exec(graphQlRequests.videoChoice())
        // Capture the second WebSocket message here.....
        .exec(graphQlRequests.onlineStatus(true))
        .pause(15)
        .exec(graphQlRequests.onlineStatus(false))

What is the best way to capture the second request? Do I need to open up a separate SSE connection?

CodePudding user response:

That's a similar issue as https://github.com/gatling/gatling/issues/3809.

In short, the expected WebSocket inbound message might have already been received between your HTTP request and your WebSocket await, so the latter misses it.

You're welcome to help with specifying a proper solution on our bug tracker (but no "upvote", "me too" or " 1" please, it doesn't help in any way and doesn't make things happen faster).

  • Related