Socket on message event isn't firing

Below is my current k6 function that will open a connection, and then send a bunch of HTTP requests (callback) to my Azure Bot Service. However, the on(‘message’) event will never be fired, am I missing something here?

    export const openSocketConnection = (socketURL, callback) => {
    ws.connect(socketURL, function (socket) {
        socket.on('open', function open() {
        socket.on('message', function (message) {

        socket.on('close', function () {

Hi @phuhnguyen,

K6 unfortuantely doesn’t have “real” global event loop and so what ws.connect does is that it blocks until the connection is closed and calls the provided functions when an event occurs … but if one of the functions/callbacks gets blocked or closes the connection it will again be closed.

As far as I can see you do call some callback function in open and than you close the connection. So given tha above 2 things happen:

  1. While open is being executed message won’t be so if callback takes a while it will not get any calls to message
  2. You close the connection right after this so … message again will not have time to be called.

Hope this helps and good luck

The context is that Azure Bot Service uses HTTP request to send data but receive the response via Web Socket, thus I’m seeking out a way to simultaneously send HTTP request and receive data via Web Socket. Is it possible?

No, but I am pretty sure that if you don’t close the socket immediately you will get the message, but your mileage might vary.