mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user