Commit 17b4a863 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

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: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 42f61ec0
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment