Skip to content

Commit

Permalink
fix(op-node): handle async disconnects to avoid test flakiness (ether…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe-op authored Apr 2, 2024
1 parent 4e88a61 commit 5bafdda
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions op-node/p2p/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,23 @@ func TestP2PFull(t *testing.T) {
require.Nil(t, err)
data = peerDump.Peers[hostBId]
require.NotNil(t, data)
require.NoError(t, p2pClientA.DisconnectPeer(ctx, hostB.ID()))
peerDump, err = p2pClientA.Peers(ctx, false)
require.Nil(t, err)
data = peerDump.Peers[hostBId]
retries := 0
for {
require.NoError(t, p2pClientA.DisconnectPeer(ctx, hostB.ID()))
// disconnect may take some time which we cant control from here
// so we retry a few times increasing our wait tolerance
time.Sleep(time.Duration(retries) * time.Second)
peerDump, err = p2pClientA.Peers(ctx, false)
require.Nil(t, err)
data = peerDump.Peers[hostBId]
if data == nil {
break
}
retries++
if retries > 3 {
t.Fatal("failed to disconnect peer")
}
}
require.Nil(t, data)

// reconnect
Expand Down

0 comments on commit 5bafdda

Please sign in to comment.