From 1e68cd142a3d40776e376ff0ecd0b234c016367d Mon Sep 17 00:00:00 2001 From: Jae Kwon <53785+jaekwon@users.noreply.github.com> Date: Thu, 19 May 2022 04:20:27 -0700 Subject: [PATCH] WIP: fixing some nondeterministic tests (#132) --- pkgs/p2p/switch_test.go | 10 +++++----- pkgs/p2p/transport_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkgs/p2p/switch_test.go b/pkgs/p2p/switch_test.go index 94397e72cd7..e0aef62d925 100644 --- a/pkgs/p2p/switch_test.go +++ b/pkgs/p2p/switch_test.go @@ -415,7 +415,7 @@ func TestSwitchReconnectsToInboundPersistentPeer(t *testing.T) { conn, err := rp.Dial(sw.NetAddress()) require.NoError(t, err) - time.Sleep(50 * time.Millisecond) + time.Sleep(100 * time.Millisecond) require.NotNil(t, sw.Peers().Get(rp.ID())) conn.Close() @@ -499,7 +499,7 @@ func TestSwitchAcceptRoutine(t *testing.T) { } }(c) } - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) // 2. check we close new connections if we already have MaxNumInboundPeers peers @@ -509,7 +509,7 @@ func TestSwitchAcceptRoutine(t *testing.T) { require.NoError(t, err) // check conn is closed one := make([]byte, 1) - conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) + conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond)) _, err = conn.Read(one) assert.Equal(t, io.EOF, err) assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) @@ -614,7 +614,7 @@ func TestSwitchInitPeerIsNotCalledBeforeRemovePeer(t *testing.T) { _, err = rp.Dial(sw.NetAddress()) require.NoError(t, err) // wait till the switch adds rp to the peer set - time.Sleep(50 * time.Millisecond) + time.Sleep(100 * time.Millisecond) // stop peer asynchronously go sw.StopPeerForError(sw.Peers().Get(rp.ID()), "test") @@ -623,7 +623,7 @@ func TestSwitchInitPeerIsNotCalledBeforeRemovePeer(t *testing.T) { _, err = rp.Dial(sw.NetAddress()) require.NoError(t, err) // wait till the switch adds rp to the peer set - time.Sleep(50 * time.Millisecond) + time.Sleep(100 * time.Millisecond) // make sure reactor.RemovePeer is finished before InitPeer is called assert.False(t, reactor.InitCalledBeforeRemoveFinished()) diff --git a/pkgs/p2p/transport_test.go b/pkgs/p2p/transport_test.go index 17ed5202e90..57b1d757f2c 100644 --- a/pkgs/p2p/transport_test.go +++ b/pkgs/p2p/transport_test.go @@ -98,7 +98,7 @@ func TestTransportMultiplexConnFilterTimeout(t *testing.T) { MultiplexTransportFilterTimeout(5 * time.Millisecond)(mt) MultiplexTransportConnFilters( func(_ ConnSet, _ net.Conn, _ []net.IP) error { - time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) return nil }, )(mt) @@ -239,18 +239,18 @@ func TestFlappyTransportMultiplexAcceptNonBlocking(t *testing.T) { select { case <-fastc: // Fast peer connected. - case <-time.After(50 * time.Millisecond): + case <-time.After(100 * time.Millisecond): // We error if the fast peer didn't succeed. errc <- fmt.Errorf("Fast peer timed out") } - sc, err := upgradeSecretConn(c, 20*time.Millisecond, ed25519.GenPrivKey()) + sc, err := upgradeSecretConn(c, 100*time.Millisecond, ed25519.GenPrivKey()) if err != nil { errc <- err return } - _, err = handshake(sc, 20*time.Millisecond, + _, err = handshake(sc, 100*time.Millisecond, testNodeInfo( ed25519.GenPrivKey().PubKey().Address().ID(), "slow_peer", @@ -549,7 +549,7 @@ func TestTransportHandshake(t *testing.T) { t.Fatal(err) } - ni, err := handshake(c, 20*time.Millisecond, emptyNodeInfo()) + ni, err := handshake(c, 100*time.Millisecond, emptyNodeInfo()) if err != nil { t.Fatal(err) }