@@ -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.
2827func 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