Hi Team,
I am using K6 to carry out performance test for our products. However, I met an issue recently and have no idea how to resolve it. Really appreciate if you can help me.
The problem is that I implemented the websocket connection with the example code described in document like below:
var response = ws.connect(url, params, function (socket) {
socket.on('open', function open() {
console.log('connected');
socket.send(Date.now());
socket.setInterval(function timeout() {
socket.ping();
console.log("Pinging every 1sec (setInterval test)");
}, 1000);
});
socket.on('ping', function () {
console.log("PING!");
});
socket.on('pong', function () {
console.log("PONG!");
});
socket.on('pong', function () {
// Multiple event handlers on the same event
console.log("OTHER PONG!");
});
socket.on('message', function (message) {
console.log(`Received message: ${message}`);
});
socket.on('close', function () {
console.log('disconnected');
});
socket.on('error', function (e) {
if (e.error() != "websocket: close sent") {
console.log('An unexpected error occured: ', e.error());
}
});
socket.setTimeout(function () {
console.log('2 seconds passed, closing the socket');
socket.close();
}, 2000);
});
I can confirmed websocket was working well originally during the performance test. But sometimes, the error was captured during the life of websocket connection. I tried to print out the error with the following code
if (e.error() != "websocket: close sent") {
console.log('An unexpected error occured: ', e.error());
}
Then I always got Cannot read property ‘error’ of undefined exception. Without error information, we cannot figure out what reason caused the Websocket issue. It would be grateful if you are able to help me.
Regards,
Johnny