I am using Gatling 2.2.5 and trying to achieve the following:
open a websocket
send a HTTP POST request that triggers a server-side process that eventually sends a message to the websocket
wait for the websocket response
save a match from the websocket response
My original attempt for this has a race condition where the server-side process may complete before I start waiting for the websocket response (simplified snippet for demonstration):
.exec(ws(“Open websocket”).open("/"))
.exec(
http(“Trigger server-side process”)
.post("/path/to/process")
.check(status.is(201))
)
// race condition: WebSocket response may have already been sent here
.exec(
ws(“Await response”)
.sendText("""{“event”:“ping”}""") // send an arbitrary message to enable setting a check
.check(wsAwait.within(300 seconds).until(1).regex("""^(.“event”:“success”.)""").saveAs(“ws_response”)
)
I am now trying to achieve a flow which removes this race condition but the Gatling DSL does not seem to quite support what I want:
.exec(ws(“Open websocket”).open("/"))
.exec(
ws(“Listen non-blocking for response”)
.sendText("""{“event”:“ping”}""") // send an arbitrary message to enable setting a check
.check(wsListen.within(300 seconds).until(1).regex("""^(.“event”:“success”.)""").saveAs(“ws_response”)
.exec(
http(“Trigger server-side process”)
.post("/path/to/process")
.check(status.is(201))
)
.exec(ws(“Reconciliate WebSocket and HTTP states”).reconciliate)
From experimentation and looking at the source code, it seems that reconciliate immediately cancels any pending checks, causing my script to fail. I want to wait until the websocket response has occurred and capture the saved variable into the session for future requests. I have tried making use of asLongAs
, during
et al but they do not seem to have access to the websocket state until reconciliate is called.