mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
fix: data race in test
https://build.protocol-dev.com/job/race/9352/console @jbenet @whyrusleeping pinging you guys to spread awareness about the delay.D type for configurable delays License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:

committed by
Juan Batiz-Benet

parent
06d4df23f1
commit
3f9c1263ec
@ -19,6 +19,7 @@ import (
|
||||
wantlist "github.com/jbenet/go-ipfs/exchange/bitswap/wantlist"
|
||||
peer "github.com/jbenet/go-ipfs/peer"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
"github.com/jbenet/go-ipfs/util/delay"
|
||||
eventlog "github.com/jbenet/go-ipfs/util/eventlog"
|
||||
pset "github.com/jbenet/go-ipfs/util/peerset"
|
||||
)
|
||||
@ -37,7 +38,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
rebroadcastDelay = time.Second * 10
|
||||
rebroadcastDelay = delay.Fixed(time.Second * 10)
|
||||
)
|
||||
|
||||
// New initializes a BitSwap instance that communicates over the provided
|
||||
@ -250,7 +251,7 @@ func (bs *bitswap) clientWorker(parent context.Context) {
|
||||
|
||||
ctx, cancel := context.WithCancel(parent)
|
||||
|
||||
broadcastSignal := time.After(rebroadcastDelay)
|
||||
broadcastSignal := time.After(rebroadcastDelay.Get())
|
||||
defer cancel()
|
||||
|
||||
for {
|
||||
@ -258,7 +259,7 @@ func (bs *bitswap) clientWorker(parent context.Context) {
|
||||
case <-broadcastSignal:
|
||||
// Resend unfulfilled wantlist keys
|
||||
bs.sendWantlistToProviders(ctx, bs.wantlist)
|
||||
broadcastSignal = time.After(rebroadcastDelay)
|
||||
broadcastSignal = time.After(rebroadcastDelay.Get())
|
||||
case ks := <-bs.batchRequests:
|
||||
if len(ks) == 0 {
|
||||
log.Warning("Received batch request for zero blocks")
|
||||
|
@ -208,9 +208,8 @@ func TestSendToWantingPeer(t *testing.T) {
|
||||
defer sg.Close()
|
||||
bg := blocksutil.NewBlockGenerator()
|
||||
|
||||
oldVal := rebroadcastDelay
|
||||
rebroadcastDelay = time.Second / 2
|
||||
defer func() { rebroadcastDelay = oldVal }()
|
||||
prev := rebroadcastDelay.Set(time.Second / 2)
|
||||
defer func() { rebroadcastDelay.Set(prev) }()
|
||||
|
||||
peerA := sg.Next()
|
||||
peerB := sg.Next()
|
||||
|
Reference in New Issue
Block a user