Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimistic provide ci checks in tests #833

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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