Merge pull request #4291 from filecoin-project/steb/node-test-races

make pledge test pass with the race detector
This commit is contained in:
Łukasz Magiera 2020-10-10 11:54:25 +02:00 committed by GitHub
commit 2db8b7efa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package test
import ( import (
"context" "context"
"fmt" "fmt"
"sync/atomic"
"os" "os"
"strings" "strings"
@ -31,7 +32,9 @@ func init() {
} }
func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) { 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) n, sn := b(t, OneFull, OneMiner)
client := n[0].FullNode.(*impl.FullNodeAPI) client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0] miner := sn[0]
@ -46,11 +49,11 @@ func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSect
} }
build.Clock.Sleep(time.Second) build.Clock.Sleep(time.Second)
mine := true mine := int64(1)
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
defer close(done) defer close(done)
for mine { for atomic.LoadInt64(&mine) != 0 {
build.Clock.Sleep(blocktime) build.Clock.Sleep(blocktime)
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) { 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) pledgeSectors(t, ctx, miner, nSectors, 0, nil)
mine = false atomic.StoreInt64(&mine, 0)
<-done <-done
} }