Skip to content

Commit

Permalink
p2p/test: fix flaky notification test (#2051)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Feb 3, 2023
1 parent 8c198c6 commit 079dbfa
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions p2p/test/notifications/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,28 @@ func TestListenAddressNotif(t *testing.T) {
require.Equal(t, []ma.Multiaddr{initialAddr}, listenAddrs)

// now start listening on another address
var newAddr ma.Multiaddr
require.NoError(t, h.Network().Listen(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1")))
var addedAddr ma.Multiaddr
select {
case e := <-sub.Out():
ev := e.(event.EvtLocalAddressesUpdated)
require.Empty(t, ev.Removed)
require.Len(t, ev.Current, 2)
require.Equal(t, ev.Current[0], event.UpdatedAddress{Address: initialAddr, Action: event.Maintained})
require.Equal(t, ev.Current[1].Action, event.Added)
newAddr = ev.Current[1].Address
_, err = newAddr.ValueForProtocol(ma.P_QUIC_V1)
var maintainedAddr ma.Multiaddr
for _, e := range ev.Current {
switch e.Action {
case event.Added:
addedAddr = e.Address
case event.Maintained:
maintainedAddr = e.Address
default:
t.Fatal("unexpected action")
}
}
require.Equal(t, initialAddr, maintainedAddr)
_, err = addedAddr.ValueForProtocol(ma.P_QUIC_V1)
require.NoError(t, err)
portStr, err := newAddr.ValueForProtocol(ma.P_UDP)
portStr, err := addedAddr.ValueForProtocol(ma.P_UDP)
require.NoError(t, err)
require.NotZero(t, portFromString(t, portStr))
case <-time.After(500 * time.Millisecond):
Expand All @@ -77,5 +86,5 @@ func TestListenAddressNotif(t *testing.T) {
require.NoError(t, err)
require.Len(t, listenAddrs, 2)
require.Contains(t, listenAddrs, initialAddr)
require.Contains(t, listenAddrs, newAddr)
require.Contains(t, listenAddrs, addedAddr)
}

0 comments on commit 079dbfa

Please sign in to comment.