diff --git a/p2p/security/tls/transport_test.go b/p2p/security/tls/transport_test.go index fb8d788b06..d49730f304 100644 --- a/p2p/security/tls/transport_test.go +++ b/p2p/security/tls/transport_test.go @@ -16,6 +16,7 @@ import ( mrand "math/rand" "net" "runtime" + "strings" "testing" "time" @@ -73,6 +74,13 @@ func connect(t *testing.T) (net.Conn, net.Conn) { return conn, sconn } +func isWindowsTCPCloseError(err error) bool { + if runtime.GOOS != "windows" { + return false + } + return strings.Contains(err.Error(), "wsarecv: An existing connection was forcibly closed by the remote host") +} + func TestHandshakeSucceeds(t *testing.T) { clientID, clientKey := createPeer(t) serverID, serverKey := createPeer(t) @@ -498,8 +506,9 @@ func TestInvalidCerts(t *testing.T) { case err := <-clientErrChan: require.Error(t, err) if err.Error() != "remote error: tls: error decrypting message" && - err.Error() != "remote error: tls: bad certificate" { - t.Fatalf("unexpected error: %s", err.Error()) + err.Error() != "remote error: tls: bad certificate" && + !isWindowsTCPCloseError(err) { + t.Errorf("unexpected error: %s", err.Error()) } case <-time.After(250 * time.Millisecond): t.Fatal("expected the server handshake to return") @@ -540,7 +549,9 @@ func TestInvalidCerts(t *testing.T) { t.Fatal("expected the server handshake to return") } require.Error(t, serverErr) - require.Contains(t, serverErr.Error(), "remote error: tls:") + if !isWindowsTCPCloseError(serverErr) { + require.Contains(t, serverErr.Error(), "remote error: tls:") + } }) } }