fix(test): TestFindPeerQuery and TestFindPeerQueryMinimal now refresh DHT routing tables before running. TestFindPeerQuery no longer runs with the race detector because it uses too many goroutines.

This commit is contained in:
Adin Schmahmann 2020-03-26 19:37:15 -04:00
parent 314213d5d8
commit f43d422675
3 changed files with 14 additions and 6 deletions

View File

@ -37,6 +37,8 @@ import (
travisci "github.com/libp2p/go-libp2p-testing/ci/travis"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
ma "github.com/multiformats/go-multiaddr"
detectrace "github.com/ipfs/go-detect-race"
)
var testCaseCids []cid.Cid
@ -1364,6 +1366,10 @@ func TestFindPeerQueryMinimal(t *testing.T) {
}
func TestFindPeerQuery(t *testing.T) {
if detectrace.WithRace() {
t.Skip("skipping due to race detector max goroutines")
}
if testing.Short() {
t.Skip("skipping test in short mode")
}
@ -1403,10 +1409,15 @@ func testFindPeerQuery(t *testing.T,
connect(t, ctx, guy, others[i])
}
for _, d := range dhts {
if err := <-d.RefreshRoutingTable(); err != nil {
t.Fatal(err)
}
}
var reachableIds []peer.ID
for i, d := range dhts {
lp := len(d.host.Network().Peers())
//t.Log(i, lp)
if i != 0 && lp > 0 {
reachableIds = append(reachableIds, d.PeerID())
}
@ -1416,11 +1427,6 @@ func testFindPeerQuery(t *testing.T,
val := "foobar"
rtval := kb.ConvertKey(val)
rtablePeers := guy.routingTable.NearestPeers(rtval, guy.alpha)
assert.Len(t, rtablePeers, minInt(bootstrappers, guy.alpha))
assert.Len(t, guy.host.Network().Peers(), bootstrappers)
out, err := guy.GetClosestPeers(ctx, val)
require.NoError(t, err)

1
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/hashicorp/golang-lru v0.5.4
github.com/ipfs/go-cid v0.0.5
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ipfs-util v0.0.1
github.com/ipfs/go-log v1.0.2
github.com/jbenet/goprocess v0.1.3

1
go.sum
View File

@ -137,6 +137,7 @@ github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec h1:DQqZhhDvrTrEQ3Q
github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs=
github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
github.com/jbenet/go-detect-race v0.0.0-20150302022421-3463798d9574/go.mod h1:gynVu6LUw+xMXD3XEvjHQcIbJkWEamnGjJDebRHqTd0=
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 h1:vhC1OXXiT9R2pczegwz6moDvuRpggaroAXhPIseh57A=
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2/go.mod h1:8GXXJV31xl8whumTzdZsTt3RnUIiPqzkyf7mxToRCMs=
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5fcGNuQzp6IGzYQSenLEgH3s6jkXrWw=