Skip to content

Commit

Permalink
peering: add logs before many-second waits
Browse files Browse the repository at this point in the history
This test takes a full minute to run, and I was honestly thinking my run
of "go test -v" had simply hung, as I saw no output and no apparent
resource usage.

The least we can do is print a few log messages before the potentially
long waits, to hint that we're still making progress. Each of these
"Eventually" and "Never" calls ends up blocking the test for a few
seconds at a time.
  • Loading branch information
mvdan committed Feb 6, 2021
1 parent 884a5ae commit 5e0c8bb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions peering/peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func TestPeeringService(t *testing.T) {
require.NoError(t, ps1.Start())

// We should eventually connect.
t.Logf("waiting for h1 to connect to h2")
require.Eventually(t, func() bool {
return h1.Network().Connectedness(h2.ID()) == network.Connected
}, 30*time.Second, 10*time.Millisecond)

// Now explicitly connect to p3.
// Now explicitly connect to h3.
t.Logf("waiting for h1's connection to h3 to work")
require.NoError(t, h1.Connect(ctx, peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}))
require.Eventually(t, func() bool {
return h1.Network().Connectedness(h2.ID()) == network.Connected
Expand All @@ -72,7 +74,8 @@ func TestPeeringService(t *testing.T) {
// force a disconnect
h1.ConnManager().TrimOpenConns(ctx)

// Should disconnect from p3.
// Should disconnect from h3.
t.Logf("waiting for h1's connection to h3 to disconnect")
require.Eventually(t, func() bool {
return h1.Network().Connectedness(h3.ID()) != network.Connected
}, 5*time.Second, 10*time.Millisecond)
Expand All @@ -88,6 +91,7 @@ func TestPeeringService(t *testing.T) {
h2.ConnManager().TrimOpenConns(ctx)

// All conns to peer should eventually close.
t.Logf("waiting for all connections to close")
for _, c := range conns {
require.Eventually(t, func() bool {
s, err := c.NewStream(context.Background())
Expand All @@ -110,18 +114,21 @@ func TestPeeringService(t *testing.T) {
h1.ConnManager().TrimOpenConns(ctx)

// Should disconnect
t.Logf("waiting for h1 to disconnect from h2")
require.Eventually(t, func() bool {
return h1.Network().Connectedness(h2.ID()) != network.Connected
}, 5*time.Second, 10*time.Millisecond)

// Should never reconnect.
t.Logf("ensuring h1 is not connected to h2 again")
require.Never(t, func() bool {
return h1.Network().Connectedness(h2.ID()) == network.Connected
}, 20*time.Second, 1*time.Second)

// Until added back
ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
ps1.AddPeer(peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()})
t.Logf("wait for h1 to connect to h2 and h3 again")
require.Eventually(t, func() bool {
return h1.Network().Connectedness(h2.ID()) == network.Connected
}, 30*time.Second, 1*time.Second)
Expand Down

0 comments on commit 5e0c8bb

Please sign in to comment.