Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/test: fix flaky notification test #2051

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}