Send ping heartbeats to server

I am trying to test a scenario with gatling tool, where I connect to server using websockets and then wait for message from server (which could take a few minutes). However, I get disconnected after 60 seconds (because socket is idle).

Reading through GitHub issues, I found out that Gatling should automatically respond with ‘pong’ to ‘ping’ messages, which does not work for me.

I have tried to implement ping/pong mechanism by sending ‘ping’ message and then pausing for 30 seconds, but then it needs up to 30 seconds from when message was received before execution continues.

Example:

val ping =

asLongAs(session => session(“message_received”).as[String] == “false”) {

exec(

ws(“Reconciliate states”).reconciliate

)

ws(“ping”)

.sendText(“ping”).pause(30)

}

def testScenario = scenario(“test scenario”)

exec(

ws(“Connect”)

.open(“ws://some-socket-address”)

)

.exec(

ws(“Wait for some message”)

.check(wsListen.within(1000).until(1).regex(“some check for event”).exists.saveAs(“message_received”))

)

.exec(ping)

.exec(

ws(“send a message, when previous message is received”)

.sendText(“some text to send”)

)

.exec(ws(“Close socket”).close)

}

In above example, ping starts executing because wsListen does not block when listening for messages. But if a message is received, up to 30 seconds is needed to complete .exec(ping) and continue to next .exec.

Is there a better way to solve this, without decreasing ping interval?

I’m afraid it’s not possible atm. What’s you’d need is an “automatic ping” feature to be implemented. Contributions welcome!
Note that the WebSocket support implementation is going away in Gatling 3 and some things change, typically wsListen is going again for now.
Also note that you’re using a ping text frame, not a ping frame.

Cheers,