Currently i’m working on the loadtest for websocket, then I got so much errors like this
Then i would to count how many errors that occurs, and provide it on the report. And I tried this method:
let errHandshake = new Counter("error_handshake");
if (res.status === 101) {
errHandshake.add(0);
} else {
errHandshake.add(1);
}
But it didnt work, the report just shown 0.
like this
Can anyone have an idea or something that might help?
Thanks a lot anyway!
Tried using try catch method and it works perfectly!!
try {
// your ws.connect
// check for example
} catch(e) {
// here you can count it ... by for example increasing a Counter
// https://k6.io/docs/javascript-api/k6-metrics/counter
}
// this code will get executed regardless if there was an exception
// so you might want to do `throw e` in the catch if you don't want that
refference: https://community.k6.io/t/how-to-count-bad-handshake-websocket/1038