k6 icon indicating copy to clipboard operation
k6 copied to clipboard

websockets protocol

Open Mahdi-Ba opened this issue 1 year ago • 1 comments

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

Mahdi-Ba avatar Jul 07 '24 19:07 Mahdi-Ba

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));
	}
}

mstoykov avatar Jul 08 '24 07:07 mstoykov

I am closing thias the there is no new information. Please comment here if you still have this problem with more information

mstoykov avatar Sep 11 '24 09:09 mstoykov