0

I want to connect to a web socket through gatling. But it is not working. The socket listener does not get any messsage. The code is given below.Can anyone suggest the problem? Is there any recording option for websocket in gatling. the recorder only record http requests.

 `val scn = scenario("RecordedSimulation")
    .exec(http("login")
               .post("/user/login")
               .formParam("email", "username")
               .formParam("password", "*******")
               .check(headerRegex("Set-Cookie", "localhost:1337.sid=(.*); Path=/").saveAs("cookie")))
    .pause(5)


    .exec(http("get sid")
        .get("/socket.io/?EIO=3&transport=polling&t=1468496890883-0")
        .headers(headers_3)
        .check(regex("\"sid\":\"(.*)\",").saveAs("sid"))
        )
    .pause(4)

    .exec(ws("Connect WebSocket").open("/socket.io/?EIO=3&transport=websocket&sid=${sid}")
         .headers(Map(
    "Accept-Encoding" -> "gzip, deflate, sdch",
    "Accept-Language" -> "en-US,en;q=0.8",
    "Pragma" -> "no-cache",
    "Host" -> "localhost:1337",
    "Cache-Control" -> "no-cache",
    "Connection" -> "Upgrade",
    "Origin" -> "http://localhost:1337",
    "Sec-WebSocket-Extensions" -> "permessage-deflate; client_max_window_bits",
    "Sec-WebSocket-Key" -> "sBWXugNrGCMSXmO3BEm4yw==",
    "Sec-WebSocket-Version" -> "13",
    "Upgrade" ->"websocket",
    "Cookie" -> "io=${sid}; __cfduid=d1cf62d5cf275e2c709080ad7610da8b61465800778; cf_clearance=42068d23995e3243b3ee748ac616389d5cc27d92-1468865525-1800; _gat=1; _ga=GA1.2.1134427855.1467369017; localhost:1337.sid=${cookie}"
    )))

    .pause(1)




    .exec(http("Run")
        .post("/posturl")
        .headers(headers_13)
        .body(RawFileBody("RecordedSimulation_0013_request.txt")))

    .exec(ws("Set Check for instance ID")
          .check(wsAwait.within(30).until(1).regex("\"intInstanceID\":\"(.*-.*-.*-.*-.*)\",").saveAs("instanceID")))
    .pause(1)

    .exec(ws("Say Hello WS")
        .sendText("""{"text": "Hello, I'm ${sid}"}"""))

    .exec( session =>{
        println(session("cookie").as[String])
        session
        })




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

}`

megamind
  • 627
  • 9
  • 17

1 Answers1

0

You don't say how your expected incoming messages are related to your other actions, but beware that we don't currently buffer unmatched incoming messages. So if a messages arrives before you actually set a check, it's lost.

If you have some feedback about your WebSocket load test usage, please share and discuss on our mailing list. There's an ongoing effort to redesign WebSocket support for Gatling 3.

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
  • the message looks like ["verdict", {verdict: {"intInstanceID": "e5756a90-4e4b-11e6-821d-6f538bb257b2", "intOutput": "Running", "instanceID": "e5756a90-4e4b-11e6-821d-6f538bb257b"}}] – megamind Jul 20 '16 at 07:37
  • I have also tried wsListen() in place of wsAwait before sending the last post request which actually triggers the server to send message. BUt it does not find anything. – megamind Jul 20 '16 at 07:39
  • No, you don't get it. What does your expected incoming come from? Is it a reaction from ws("Connect WebSocket") or http("Run")? If so, what if the message is actually received BEFORE you call ws("Set Check for instance ID")? – Stephane Landelle Jul 20 '16 at 09:43
  • it comes from http("Run") – megamind Jul 20 '16 at 10:06
  • So if the message arrives before you set the check, it's lost. – Stephane Landelle Jul 20 '16 at 10:19
  • Please join our mailing list and explain your use case and why it makes sense to send a plain HTTP request and receive a response over WebSocket. – Stephane Landelle Jul 20 '16 at 10:21
  • actually, the http response is not sent through the socket, the post request only triggers the server to start communicating through the socket after a while the request is sent. – megamind Jul 20 '16 at 18:34