From cc4a63e454ff4067c7b347f7ce59cf5b46f05037 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 15 Nov 2021 12:18:34 +0300 Subject: [PATCH 1/2] rpc/server: use dynamic port for P2P service Fix running tests alongside regular testnet node. panic: TCP listen error goroutine 4634 [running]: go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc0008540c0, 0xc001a4df80, 0x1, 0x1) /home/rik/go/pkg/mod/go.uber.org/zap@v1.18.1/zapcore/entry.go:234 +0x532 go.uber.org/zap.(*Logger).Panic(0xc002399ce0, 0xecd669, 0x10, 0xc001a4df80, 0x1, 0x1) /home/rik/go/pkg/mod/go.uber.org/zap@v1.18.1/logger.go:230 +0x85 github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Accept(0xc000fd6960) /home/rik/dev/neo-go/pkg/network/tcp_transport.go:49 +0x216 created by github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start /home/rik/dev/neo-go/pkg/network/server.go:292 +0x2bb FAIL github.com/nspcc-dev/neo-go/pkg/rpc/server 1.095s --- pkg/rpc/server/server_helper_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/rpc/server/server_helper_test.go b/pkg/rpc/server/server_helper_test.go index 6dbb23608..a746ca5e8 100644 --- a/pkg/rpc/server/server_helper_test.go +++ b/pkg/rpc/server/server_helper_test.go @@ -101,6 +101,7 @@ func initClearServerWithServices(t testing.TB, needOracle bool, needNotary bool) chain, orc, cfg, logger := getUnitTestChain(t, needOracle, needNotary) serverConfig := network.NewServerConfig(cfg) + serverConfig.Port = 0 server, err := network.NewServer(serverConfig, chain, logger) require.NoError(t, err) rpcServer := New(chain, cfg.ApplicationConfiguration.RPC, server, orc, logger) From 48de82d902f9c758ead8364c60a87bd8b625722c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 15 Nov 2021 12:37:01 +0300 Subject: [PATCH 2/2] network: fix data race in TestHandleMPTData, fix #2241 --- pkg/network/server_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/network/server_test.go b/pkg/network/server_test.go index 51e9fe633..6cc83d3fc 100644 --- a/pkg/network/server_test.go +++ b/pkg/network/server_test.go @@ -141,11 +141,7 @@ func TestServerRegisterPeer(t *testing.T) { ps[i].netaddr.Port = i + 1 } - ch := startWithChannel(s) - t.Cleanup(func() { - s.Shutdown() - <-ch - }) + startWithCleanup(t, s) s.register <- ps[0] require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10) @@ -395,12 +391,16 @@ func startTestServer(t *testing.T, protocolCfg ...func(*config.ProtocolConfigura } else { s = newTestServer(t, srvCfg) } + startWithCleanup(t, s) + return s +} + +func startWithCleanup(t *testing.T, s *Server) { ch := startWithChannel(s) t.Cleanup(func() { s.Shutdown() <-ch }) - return s } func TestBlock(t *testing.T) { @@ -826,8 +826,8 @@ func TestHandleMPTData(t *testing.T) { }) t.Run("good", func(t *testing.T) { - s := startTestServer(t) expected := [][]byte{{1, 2, 3}, {2, 3, 4}} + s := newTestServer(t, ServerConfig{Port: 0, UserAgent: "/test/"}) s.chain.(*fakechain.FakeChain).P2PStateExchangeExtensions = true s.stateSync = &fakechain.FakeStateSync{ AddMPTNodesFunc: func(nodes [][]byte) error { @@ -835,6 +835,7 @@ func TestHandleMPTData(t *testing.T) { return nil }, } + startWithCleanup(t, s) p := newLocalPeer(t, s) p.handshaked = true