@@ -18,6 +18,49 @@ import (
1818 mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
1919)
2020
21+ func TestHang (t * testing.T ) {
22+ ctx := context .Background ()
23+ mn , err := mocknet .FullMeshConnected (ctx , 2 )
24+ if err != nil {
25+ t .Fatal (err )
26+ }
27+ hosts := mn .Hosts ()
28+
29+ os := []opts.Option {opts .DisableAutoRefresh ()}
30+ d , err := New (ctx , hosts [0 ], os ... )
31+ if err != nil {
32+ t .Fatal (err )
33+ }
34+ // Hang on every request.
35+ hosts [1 ].SetStreamHandler (d .protocols [0 ], func (s network.Stream ) {
36+ defer s .Reset ()
37+ <- ctx .Done ()
38+ })
39+ d .Update (ctx , hosts [1 ].ID ())
40+
41+ ctx1 , cancel1 := context .WithTimeout (ctx , 1 * time .Second )
42+ defer cancel1 ()
43+
44+ peers , err := d .GetClosestPeers (ctx1 , testCaseCids [0 ].KeyString ())
45+ if err != nil {
46+ t .Fatal (err )
47+ }
48+
49+ time .Sleep (100 * time .Millisecond )
50+ ctx2 , cancel2 := context .WithTimeout (ctx , 100 * time .Millisecond )
51+ defer cancel2 ()
52+ _ = d .Provide (ctx2 , testCaseCids [0 ], true )
53+ if ctx2 .Err () != context .DeadlineExceeded {
54+ t .Errorf ("expected to fail with deadline exceeded, got: %s" , ctx2 .Err ())
55+ }
56+ select {
57+ case <- peers :
58+ t .Error ("GetClosestPeers should not have returned yet" )
59+ default :
60+ }
61+
62+ }
63+
2164func TestGetFailures (t * testing.T ) {
2265 if testing .Short () {
2366 t .SkipNow ()
0 commit comments