network: take care of TestServerStartAndShutdown

We don't have a reliable way to know when transports are started since
their start is being performed in a separate goroutine:

927dbb6dc4/pkg/network/server.go (L297-L299)

And transports start is not connected with main server routine, thus,
just wait for some time for the transports goroutine to be started.

Also wait for the peer to be properly registered.

Close #3399.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-04-04 13:26:44 +03:00
parent 927dbb6dc4
commit f84f072a29

View file

@ -95,8 +95,10 @@ func TestServerStartAndShutdown(t *testing.T) {
s.register <- p s.register <- p
require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10) require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10)
assert.True(t, s.transports[0].(*fakeTransp).started.Load())
require.True(t, s.started.Load()) require.True(t, s.started.Load())
require.Eventually(t, func() bool {
return s.transports[0].(*fakeTransp).started.Load()
}, 2*time.Second, 200*time.Millisecond)
assert.Nil(t, s.txCallback) assert.Nil(t, s.txCallback)
s.Shutdown() s.Shutdown()
@ -115,6 +117,7 @@ func TestServerStartAndShutdown(t *testing.T) {
s.Start() s.Start()
p := newLocalPeer(t, s) p := newLocalPeer(t, s)
s.register <- p s.register <- p
require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10)
assert.True(t, s.services["fake"].(*fakeConsensus).started.Load()) assert.True(t, s.services["fake"].(*fakeConsensus).started.Load())
require.True(t, s.started.Load()) require.True(t, s.started.Load())