Skip to content

Commit

Permalink
swarm: fix flaky TestDialExistingConnection test (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored May 19, 2022
1 parent b5289f1 commit d3a561e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions p2p/net/swarm/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ func TestDialExistingConnection(t *testing.T) {
s1 := swarms[0]
s2 := swarms[1]

s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses(), peerstore.PermanentAddrTTL)
// Only use one of the addresses here.
// Otherwise, we might dial TCP and QUIC simultaneously here, and end up with two connections,
// if the handshake latencies line up exactly.
s1.Peerstore().AddAddrs(s2.LocalPeer(), s2.ListenAddresses()[:1], peerstore.PermanentAddrTTL)

c1, err := s1.DialPeer(context.Background(), s2.LocalPeer())
require.NoError(t, err)
Expand All @@ -489,7 +492,7 @@ func TestDialExistingConnection(t *testing.T) {

// can't use require.Equal here, as this does a deep comparison
if c1 != c2 {
t.Fatal("expecting the same connection from both dials")
t.Fatalf("expecting the same connection from both dials, got %s <-> %s vs %s <-> %s", c1.LocalMultiaddr(), c1.RemoteMultiaddr(), c2.LocalMultiaddr(), c2.RemoteMultiaddr())
}
}

Expand Down

0 comments on commit d3a561e

Please sign in to comment.