websocket: Relay disconnect errors to subscribers (#1347)

* WS: Relay disconnect errors to subscribers

Subscribers probably care when the WS got disconncted.
Tell them and expose a method to test the error for matching

* Fix linter error
This commit is contained in:
Gareth Kirwan
2023-09-14 01:14:04 +01:00
committed by GitHub
parent bcabf44b8c
commit c8ec22fe92
3 changed files with 14 additions and 13 deletions

View File

@@ -230,11 +230,11 @@ func TestTrafficMonitorTimeout(t *testing.T) {
func TestIsDisconnectionError(t *testing.T) {
t.Parallel()
isADisconnectionError := isDisconnectionError(errors.New("errorText"))
isADisconnectionError := IsDisconnectionError(errors.New("errorText"))
if isADisconnectionError {
t.Error("Its not")
}
isADisconnectionError = isDisconnectionError(&websocket.CloseError{
isADisconnectionError = IsDisconnectionError(&websocket.CloseError{
Code: 1006,
Text: "errorText",
})
@@ -242,14 +242,14 @@ func TestIsDisconnectionError(t *testing.T) {
t.Error("It is")
}
isADisconnectionError = isDisconnectionError(&net.OpError{
isADisconnectionError = IsDisconnectionError(&net.OpError{
Err: errClosedConnection,
})
if isADisconnectionError {
t.Error("It's not")
}
isADisconnectionError = isDisconnectionError(&net.OpError{
isADisconnectionError = IsDisconnectionError(&net.OpError{
Err: errors.New("errText"),
})
if !isADisconnectionError {
@@ -321,8 +321,10 @@ func TestConnectionMessageErrors(t *testing.T) {
outer:
for {
select {
case <-ws.ToRoutine:
t.Fatal("Error is a disconnection error")
case err := <-ws.ToRoutine:
if _, ok := err.(*websocket.CloseError); !ok {
t.Errorf("Error is not a disconnection error: %v", err)
}
case <-timer.C:
break outer
}