grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
24.08k stars 1.2k forks source link

websockets protocol #3832

Open Mahdi-Ba opened 2 weeks ago

Mahdi-Ba commented 2 weeks ago

Brief summary

in websockets protocol

//below code doesn't work and didn't send to the server 

socket.send(JSON.stringify(messageObject));

//But below is working 

   socket.setInterval(function timeout() {
                socket.send(JSON.stringify(messageObject));
                console.log('message sent');
            }, 1000);

k6 version

v0.52.0

OS

macOS M1 14.3.1 (23D60) Sonoma

Docker version and image (if applicable)

No response

Steps to reproduce the problem

I submit message but any message received in server in websockets protocol

Expected behaviour

I Expected without interval I receive message too

Actual behaviour

in websockets protocol with interval, I receive But in normal behavior doesn't work

mstoykov commented 2 weeks ago

Hi @Mahdi-Ba, can you provide a full example, as I can't reproduce the problem you are having with the following script

import ws from 'k6/ws';

export default function() {
    const url = 'wss://echo.websocket.org';
    let res = ws.connect(url, function(socket) {
        socket.on('error', console.log)
        socket.on('open', function open() {
            console.log('connected');
            socket.send("hello");
            socket.setTimeout(function timeout() {
                socket.close()
            }, 1000);
            socket.setInterval(function timeout() {
                socket.send("other mesasage");
            }, 500);

        });

        socket.on('message', (msg) => console.log('message!', msg));
    });
    if (res.status != 101) {
        console.log(JSON.stringify(res));
    }
}