WebSockets on a Web test

Hi all!

I am wondering if it is possible to combine on the same test, HTTP requests and WS connections.

In a certain flow, we need to:

  1. Make some HTTP requests.
  2. Connect to a WS.
  3. Make some HTTP requests.
  4. Connect to another WS
  5. Make some HTTP requests.
  6. Wait until we receive a message on the last WS.
  7. Make some HTTP requests.
  8. Close both WSs.

I am trying to develop it, but on the second step the VU gets stucked… I suppose that it is waiting to get a message, but I am not sure…

Could someone help me please? Is it even possible to simulate that behaviour with k6?

Thanks in advanced,

I can’t say if that’s your problem without seeing the full code, but HTTP requests and websocket connections are currently synchronous in k6. That means that a ws.connect() call won’t return until the websocket connection is closed.

k6 still doesn’t have a global event loop (though we’re currently working on it!) and instead the WebSocket API has its own localized event loop. See this docs page for a more detailed example of what that looks like: Socket.on(event, callback)

1 Like