@cryptotaxi247 / kubo / commits / 5e0c8bbf2

peering: add logs before many-second waits

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.

Daniel Martí committed Feb 6, 2021 at 17:58 UTC 5e0c8bbf28e830c8a81bc81eee3633c0a176c30d
1 file changed +9 -2
peering/peering_test.go
+9 -2
@@ -57,11 +57,13 @@ func TestPeeringService(t *testing.T) {
57 require.NoError(t, ps1.Start())
58
59 // We should eventually connect.
60 + t.Logf("waiting for h1 to connect to h2")
61 require.Eventually(t, func() bool {
62 return h1.Network().Connectedness(h2.ID()) == network.Connected
63 }, 30*time.Second, 10*time.Millisecond)
64
64 - // Now explicitly connect to p3.
65 + // Now explicitly connect to h3.
66 + t.Logf("waiting for h1's connection to h3 to work")
67 require.NoError(t, h1.Connect(ctx, peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}))
68 require.Eventually(t, func() bool {
69 return h1.Network().Connectedness(h2.ID()) == network.Connected
@@ -72,7 +74,8 @@ func TestPeeringService(t *testing.T) {
74 // force a disconnect
75 h1.ConnManager().TrimOpenConns(ctx)
76
75 - // Should disconnect from p3.
77 + // Should disconnect from h3.
78 + t.Logf("waiting for h1's connection to h3 to disconnect")
79 require.Eventually(t, func() bool {
80 return h1.Network().Connectedness(h3.ID()) != network.Connected
81 }, 5*time.Second, 10*time.Millisecond)
@@ -88,6 +91,7 @@ func TestPeeringService(t *testing.T) {
91 h2.ConnManager().TrimOpenConns(ctx)
92
93 // All conns to peer should eventually close.
94 + t.Logf("waiting for all connections to close")
95 for _, c := range conns {
96 require.Eventually(t, func() bool {
97 s, err := c.NewStream(context.Background())
@@ -110,11 +114,13 @@ func TestPeeringService(t *testing.T) {
114 h1.ConnManager().TrimOpenConns(ctx)
115
116 // Should disconnect
117 + t.Logf("waiting for h1 to disconnect from h2")
118 require.Eventually(t, func() bool {
119 return h1.Network().Connectedness(h2.ID()) != network.Connected
120 }, 5*time.Second, 10*time.Millisecond)
121
122 // Should never reconnect.
123 + t.Logf("ensuring h1 is not connected to h2 again")
124 require.Never(t, func() bool {
125 return h1.Network().Connectedness(h2.ID()) == network.Connected
126 }, 20*time.Second, 1*time.Second)
@@ -122,6 +128,7 @@ func TestPeeringService(t *testing.T) {
128 // Until added back
129 ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
130 ps1.AddPeer(peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()})
131 + t.Logf("wait for h1 to connect to h2 and h3 again")
132 require.Eventually(t, func() bool {
133 return h1.Network().Connectedness(h2.ID()) == network.Connected
134 }, 30*time.Second, 1*time.Second)