k6
k6 copied to clipboard
Websockets should tag connection errors better
Currently, if an error (like timeout) happens during the creation of the websocket k6 will not emit status=0 or tags error and error_code as will the HTTP module, but will just no emit the status tag, call the error handle if defined and end continue executing javascript.
This will require for the error_code code to be made exported and possibly moved to a different module, which will impact #2008, so we might want to merge that first.
@neha13rb1998, you can define an error handler, see https://k6.io/docs/javascript-api/k6-ws/socket/socket-on-event-callback
@neha13rb1998, you can define a new custom metric (e.g. a Counter) and add() to it in the error websocket handler, see:
- https://k6.io/docs/using-k6/metrics/#custom-metrics
- https://k6.io/docs/javascript-api/k6-metrics/counter/
@neha13rb1998, move the errorCounter.add(1); in the body of the socket.on('error', function(e){ ... } function, like this:
socket.on('error', function(e){
if (e.error() != 'websocket: close sent') {
errorCounter.add(1);
console.log('An unexpected error occured: ', e.error());
}
});
Also, please don't use this github issue for support, use the community forum instead: https://community.k6.io/ (see these instructions).
#$qwerty
#$qwerty
qwertyu
A new experimental WebSocket module exists and we aim to graduate it as stable. So, I'm closing this in favor of its clone on the new module https://github.com/grafana/xk6-websockets/issues/8.