Multiple websocket connections in loop

Hi,

I would like to run the following scenario in a loop:
every new repeat of the loop contains the actions given below:

  1. create a new websocket connection;

  2. after the connection is established, a request is sent;

  3. a check is done if a response is returned;

  4. websocket connection is closed.

My script looks similar to this

val userScenario = {
  scenario("Socket.IO Load Test")
    .repeat(5, "n") {
      exec(http("Handshake")
        .get("/socket.io/1/").check(status.is(200)).check(bodyString.saveAs("uuid")))
        .exec { session =>
          var id = session("uuid").as[String]
          id = id.substring(0, id.indexOf(':'))
          session.set("sid", "/socket.io/1/websocket/" + id)
        }
        .exec(ws("Connect WS ${n}")
          .connect(session => session("sid").as[String])
          .onConnected(
            exec({
              val deviceId = UUID.randomUUID().toString
              var req = subscribeRequest.format(deviceId, deviceId)
              println(req)
              ws("Subscribe")
                .sendText(req)
                .await(1)(ws.checkTextMessage("Check")
                  .check(regex(".*"))
                )
            }).pause(30)
          ))
        .exec(ws("Close ${n}").close)
    }
}

the problem is that the check block is executed only once. Could u pls give any ideas where the problem lies?

What’s for sure is that you always have the same deviceId as you’re not creating it in a function but in a block that returns a value.

.sendText { session =>

this block was fixed to invoke the function, but it did not help, still I see that the similar request is sent every time in a loop

var subscribeRequest = """3:1::{"ID": 72001, "correlationId": "%s", "deviceId": "%s", "casinoName": "playtech47001", "clientSkin": "playtech47001", "clientVersion": "1.0", "clientType": "casino", "clientPlatform": "web", "languageCode": "EN","location": "[http://10.196.222.59:8080/licensee/index.html](http://10.196.222.59:8080/licensee/index.html)"}"""
def getSubscribeRequest(): String = {
 subscribeRequest.format(UUID.randomUUID().toString, UUID.randomUUID().toString
}

val userScenario = {
  scenario("Socket.IO Load Test")
    .repeat(5, "n") {
      exec(http("Handshake")
        .get("/[socket.io/1/](http://socket.io/1/)").check(status.is(200)).check(bodyString.saveAs("uuid")))
        .exec { session =>
          var id = session("uuid").as[String]
          id = id.substring(0, id.indexOf(':'))
          session.set("sid", "/[socket.io/1/websocket/](http://socket.io/1/websocket/)" + id)
        }
        .exec(
          ws("Connect WS ${n}")
            .connect(session =>
              session("sid").as[String]
            ).onConnected(
            exec({
              ws("Subscribe ${n}")
                .sendText(getSubscribeRequest())
            }).exec(pause(1))
              .exec(
                ws("Close ${n} ${sid}").close)

          ))
    }
}

setUp(userScenario.inject(atOnceUsers(1)).protocols(httpProtocol))

https://gatling.io/docs/current/advanced_tutorial/#step-05-check-and-failure-management

Stephane, could you pls clarify what you mean? What approach should I use to get the unique requests to be sent every time?