diff --git a/dht_test.go b/dht_test.go index c91aa4d77..9fee50898 100644 --- a/dht_test.go +++ b/dht_test.go @@ -774,19 +774,17 @@ func TestRefresh(t *testing.T) { ctxT, cancelT := context.WithTimeout(ctx, 5*time.Second) defer cancelT() - go func() { - for ctxT.Err() == nil { - bootstrap(t, ctxT, dhts) - - // wait a bit. - select { - case <-time.After(50 * time.Millisecond): - continue // being explicit - case <-ctxT.Done(): - return - } + for ctxT.Err() == nil { + bootstrap(t, ctxT, dhts) + + // wait a bit. + select { + case <-time.After(50 * time.Millisecond): + continue // being explicit + case <-ctxT.Done(): + return } - }() + } waitForWellFormedTables(t, dhts, 7, 10, 10*time.Second) cancelT() @@ -1415,6 +1413,9 @@ func testFindPeerQuery(t *testing.T, connectNoSync(t, ctx, guy, others[i]) } + // give some time for things to settle down + time.Sleep(2 * time.Second) + for _, d := range dhts { if err := <-d.RefreshRoutingTable(); err != nil { t.Fatal(err) diff --git a/ext_test.go b/ext_test.go index 7abddc74d..d714bd339 100644 --- a/ext_test.go +++ b/ext_test.go @@ -9,21 +9,23 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peerstore" + "github.com/libp2p/go-libp2p-core/protocol" "github.com/libp2p/go-libp2p-core/routing" + + pb "github.com/libp2p/go-libp2p-kad-dht/pb" + record "github.com/libp2p/go-libp2p-record" swarmt "github.com/libp2p/go-libp2p-swarm/testing" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" ggio "github.com/gogo/protobuf/io" u "github.com/ipfs/go-ipfs-util" - pb "github.com/libp2p/go-libp2p-kad-dht/pb" - record "github.com/libp2p/go-libp2p-record" - mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/stretchr/testify/require" ) // Test that one hung request to a peer doesn't prevent another request // using that same peer from obeying its context. func TestHungRequest(t *testing.T) { - t.Skip("extremely flaky") ctx := context.Background() mn, err := mocknet.FullMeshConnected(ctx, 2) if err != nil { @@ -41,6 +43,8 @@ func TestHungRequest(t *testing.T) { defer s.Reset() <-ctx.Done() }) + + require.NoError(t, hosts[0].Peerstore().AddProtocols(hosts[1].ID(), protocol.ConvertToStrings(d.protocols)...)) d.peerFound(ctx, hosts[1].ID()) ctx1, cancel1 := context.WithTimeout(ctx, 1*time.Second)