From 473a1fc24ebe537e3a7f47730832d13567193521 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 7 Jul 2021 21:01:26 +0300 Subject: [PATCH] rpc/server: fix sporadic test failures It can still be "reading" after test end: subscription_test.go:24: Error Trace: subscription_test.go:24 asm_amd64.s:1374 Error: Received unexpected error: set tcp 127.0.0.1:49874: use of closed network connection Test: TestFilteredNotaryRequestSubscriptions ================== WARNING: DATA RACE Write at 0x00c000e28989 by goroutine 185: testing.tRunner() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1126 +0x21a Previous write at 0x00c000e28989 by goroutine 192: testing.(*common).FailNow() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:731 +0x4f testing.(*T).FailNow() :1 +0x44 github.com/stretchr/testify/require.NoError() /home/runner/go/pkg/mod/github.com/stretchr/testify@v1.6.1/require/require.go:1038 +0x104 github.com/nspcc-dev/neo-go/pkg/rpc/server.wsReader() /home/runner/work/neo-go/neo-go/pkg/rpc/server/subscription_test.go:24 +0x187 Goroutine 185 (running) created at: testing.(*T).Run() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1168 +0x5bb testing.runTests.func1() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1439 +0xa6 testing.tRunner() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1123 +0x202 testing.runTests() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1437 +0x612 testing.(*M).Run() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1345 +0x3b3 main.main() _testmain.go:89 +0x236 Goroutine 192 (finished) created at: github.com/nspcc-dev/neo-go/pkg/rpc/server.initCleanServerAndWSClient() /home/runner/work/neo-go/neo-go/pkg/rpc/server/subscription_test.go:65 +0x294 github.com/nspcc-dev/neo-go/pkg/rpc/server.TestFilteredNotaryRequestSubscriptions() /home/runner/work/neo-go/neo-go/pkg/rpc/server/subscription_test.go:348 +0x68d testing.tRunner() /opt/hostedtoolcache/go/1.15.13/x64/src/testing/testing.go:1123 +0x202 ================== testing.go:1038: race detected during execution of test --- pkg/rpc/server/subscription_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/rpc/server/subscription_test.go b/pkg/rpc/server/subscription_test.go index 45f08fd23..3cd0cfd98 100644 --- a/pkg/rpc/server/subscription_test.go +++ b/pkg/rpc/server/subscription_test.go @@ -21,6 +21,10 @@ const testOverflow = false func wsReader(t *testing.T, ws *websocket.Conn, msgCh chan<- []byte, isFinished *atomic.Bool) { for { err := ws.SetReadDeadline(time.Now().Add(time.Second)) + if isFinished.Load() { + require.Error(t, err) + break + } require.NoError(t, err) _, body, err := ws.ReadMessage() if isFinished.Load() {