Я попытался воспроизвести ошибку, используя следующий скрипт, но он работает, как и ожидалось.
Просто запустите k6 run --vus 5 -i 5 script.js
import ws from "k6/ws";
import http from 'k6/http';
import { check, sleep } from "k6";
export default function () {
http.get("http://test.loadimpact.com");
console.log(`exec http.get at ${new Date(Date.now()).toLocaleString()}`)
sleep(1)
var url = "ws://echo.websocket.org";
var response = ws.connect(url, {}, function (socket) {
socket.on('open', function open() {
console.log(`VU ${__VU} ==> connected at ${new Date(Date.now()).toLocaleString()}`);
socket.ping();
});
socket.on('ping', function () {
console.log("PING!");
});
socket.on('pong', function () {
console.log("PONG!");
});
socket.on('close', function close() {
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('1 seconds passed, closing the socket');
socket.close();
}, 1000);
});
check(response, { "status is 101": (r) => r && r.status === 101 });
};
Вы увидите, что онивсе подключаются к WebSocket одновременно.
k6 run --vus 5 -i 5 script.js
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | (_) |
/ __________ \ |__| \__\ \___/ .io
execution: local
output: -
script: script.js
duration: -, iterations: 5
vus: 5, max: 5
INFO[0001] exec http.get at 05/15/2018, 12:22:11
INFO[0001] exec http.get at 05/15/2018, 12:22:11
INFO[0001] exec http.get at 05/15/2018, 12:22:11
INFO[0001] exec http.get at 05/15/2018, 12:22:11
INFO[0001] exec http.get at 05/15/2018, 12:22:11
INFO[0002] VU 2 ==> connected at 05/15/2018, 12:22:12
INFO[0002] VU 1 ==> connected at 05/15/2018, 12:22:12
INFO[0002] VU 4 ==> connected at 05/15/2018, 12:22:12
INFO[0002] VU 5 ==> connected at 05/15/2018, 12:22:12
INFO[0002] VU 3 ==> connected at 05/15/2018, 12:22:12
INFO[0002] PONG!
INFO[0002] PONG!
INFO[0002] PONG!
INFO[0002] PONG!
INFO[0002] PONG!
INFO[0003] 1 seconds passed, closing the socket
INFO[0003] disconnected
INFO[0003] 1 seconds passed, closing the socket
INFO[0003] disconnected
INFO[0003] 1 seconds passed, closing the socket
INFO[0003] disconnected
INFO[0003] 1 seconds passed, closing the socket
INFO[0003] disconnected
INFO[0003] 1 seconds passed, closing the socket
INFO[0003] disconnected