Skip to content

Commit

Permalink
WIP: fixing some nondeterministic tests (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon authored May 19, 2022
1 parent 4c9dc4b commit 1e68cd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pkgs/p2p/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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")
Expand All @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions pkgs/p2p/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 1e68cd1

Please sign in to comment.