Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Apr 1, 2020
1 parent bbe64f6 commit 1eb7008
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
25 changes: 13 additions & 12 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 1eb7008

Please sign in to comment.