Skip to content

Commit 4a78fc6

Browse files
committed
test: fix TestHungRequest bootstrap
Just wait for peers to fill up the routing table.
1 parent fb42b20 commit 4a78fc6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ext_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020

2121
ggio "github.com/gogo/protobuf/io"
2222
u "github.com/ipfs/go-ipfs-util"
23-
"github.com/stretchr/testify/require"
2423
)
2524

2625
// Test that one hung request to a peer doesn't prevent another request
2726
// using that same peer from obeying its context.
2827
func TestHungRequest(t *testing.T) {
29-
ctx := context.Background()
28+
ctx, cancel := context.WithCancel(context.Background())
29+
defer cancel()
30+
3031
mn, err := mocknet.FullMeshConnected(ctx, 2)
3132
if err != nil {
3233
t.Fatal(err)
@@ -46,8 +47,10 @@ func TestHungRequest(t *testing.T) {
4647
})
4748
}
4849

49-
require.NoError(t, hosts[0].Peerstore().AddProtocols(hosts[1].ID(), protocol.ConvertToStrings(d.serverProtocols)...))
50-
d.peerFound(ctx, hosts[1].ID(), true)
50+
// Wait at most 100ms for a peer in our routing table.
51+
for i := 0; i < 100 && d.routingTable.Size() == 0; i++ {
52+
time.Sleep(10 * time.Millisecond)
53+
}
5154

5255
ctx1, cancel1 := context.WithTimeout(ctx, 1*time.Second)
5356
defer cancel1()
@@ -66,8 +69,8 @@ func TestHungRequest(t *testing.T) {
6669
t.Errorf("expected to fail with deadline exceeded, got: %s", ctx2.Err())
6770
}
6871
select {
69-
case <-done:
70-
t.Errorf("GetClosestPeers should not have returned yet")
72+
case err = <-done:
73+
t.Error("GetClosestPeers should not have returned yet", err)
7174
default:
7275
err = <-done
7376
if err != context.DeadlineExceeded {

0 commit comments

Comments
 (0)