From f3abd1ae82d0dbd500b4fa1ccc32e6a6fe54d020 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 9 Oct 2020 20:32:09 -0700 Subject: [PATCH] make pledge test pass with the race detector --- api/test/window_post.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index 7bc56a562..28639cda8 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -3,6 +3,7 @@ package test import ( "context" "fmt" + "sync/atomic" "os" "strings" @@ -31,7 +32,9 @@ func init() { } func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { - ctx := context.Background() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + n, sn := b(t, OneFull, OneMiner) client := n[0].FullNode.(*impl.FullNodeAPI) miner := sn[0] @@ -46,11 +49,11 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect } build.Clock.Sleep(time.Second) - mine := true + mine := int64(1) done := make(chan struct{}) go func() { defer close(done) - for mine { + for atomic.LoadInt64(&mine) != 0 { build.Clock.Sleep(blocktime) if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) { @@ -62,7 +65,7 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect pledgeSectors(t, ctx, miner, nSectors, 0, nil) - mine = false + atomic.StoreInt64(&mine, 0) <-done }