Skip to content

Commit

Permalink
Merge pull request #833 from dennis-tra/optprov-ci-checks
Browse files Browse the repository at this point in the history
fix: optimistic provide ci checks in tests
  • Loading branch information
guillaumemichel authored Apr 5, 2023
2 parents 32fbe47 + 7b7193a commit f876d8b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lookup_optim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import (
"math/rand"
"testing"
"time"

"github.com/libp2p/go-libp2p-kad-dht/netsize"
"github.com/libp2p/go-libp2p/core/peer"
)

func randInt(n, except int) int {
func randInt(rng *rand.Rand, n, except int) int {
for {
r := rand.Intn(n)
r := rng.Intn(n)
if r != except {
return r
}
}
}

func TestOptimisticProvide(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rng := rand.New(rand.NewSource(time.Now().UnixNano()))

// Order of events:
// 1. setup DHTs
Expand All @@ -46,13 +46,13 @@ func TestOptimisticProvide(t *testing.T) {
// connect each DHT with three random others
for i, dht := range dhts {
for j := 0; j < 3; j++ {
r := randInt(dhtCount, i)
r := randInt(rng, dhtCount, i)
connect(t, ctx, dhts[r], dht)
}
}

// select privileged DHT that will perform the provide operation
privIdx := rand.Intn(dhtCount)
privIdx := rng.Intn(dhtCount)
privDHT := dhts[privIdx]

peerIDs := make([]peer.ID, 20)
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestOptimisticProvide(t *testing.T) {
}

for _, c := range testCaseCids {
n := randInt(dhtCount, privIdx)
n := randInt(rng, dhtCount, privIdx)

ctxT, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
Expand Down

0 comments on commit f876d8b

Please sign in to comment.