fix tests

This commit is contained in:
whyrusleeping 2020-08-06 17:05:35 -07:00
parent 32a5c52105
commit 41bc8f14a2
2 changed files with 36 additions and 30 deletions

View File

@ -132,21 +132,22 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
done := make(chan struct{}) done := make(chan struct{})
minedTwo := make(chan struct{}) minedTwo := make(chan struct{})
m2addr, err := sn[1].ActorAddress(context.TODO())
if err != nil {
t.Fatal(err)
}
go func() { go func() {
doneMinedTwo := false
defer close(done) defer close(done)
prevExpect := 0
for atomic.LoadInt32(&mine) != 0 { for atomic.LoadInt32(&mine) != 0 {
wait := make(chan int, 2) wait := make(chan int)
mdone := func(mined bool, err error) { mdone := func(mined bool, err error) {
go func() { n := 0
n := 0 if mined {
if mined { n = 1
n = 1 }
} wait <- n
wait <- n
}()
} }
if err := sn[0].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil { if err := sn[0].MineOne(ctx, miner.MineReq{Done: mdone}); err != nil {
@ -166,33 +167,27 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
continue continue
} }
for { var nodeOneMined bool
n := 0 for _, node := range sn {
for i, node := range sn { mb, err := node.MiningBase(ctx)
mb, err := node.MiningBase(ctx) if err != nil {
if err != nil { t.Error(err)
t.Error(err) return
return }
}
if len(mb.Cids()) != expect { for _, b := range mb.Blocks() {
log.Warnf("node %d mining base not complete (%d, want %d)", i, len(mb.Cids()), expect) if b.Miner == m2addr {
continue nodeOneMined = true
break
} }
n++
} }
if n == len(sn) {
break
}
time.Sleep(blocktime)
} }
if prevExpect == 2 && expect == 2 && !doneMinedTwo { if nodeOneMined {
close(minedTwo) close(minedTwo)
doneMinedTwo = true
} }
prevExpect = expect
} }
}() }()

View File

@ -6,10 +6,11 @@ import (
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"sync" "sync"
"time" "time"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
@ -162,6 +163,16 @@ func (m *Miner) mine(ctx context.Context) {
if base != nil && base.TipSet.Height() == prebase.TipSet.Height() && base.NullRounds == prebase.NullRounds { if base != nil && base.TipSet.Height() == prebase.TipSet.Height() && base.NullRounds == prebase.NullRounds {
break break
} }
if base != nil {
onDone(false, nil)
}
// TODO: need to change the orchestration here. the problem is that
// we are waiting *after* we enter this loop and selecta mining
// candidate, which is almost certain to change in multiminer
// tests. Instead, we should block before entering the loop, so
// that when the test 'MineOne' function is triggered, we pull our
// best mining candidate at that time.
// Wait until propagation delay period after block we plan to mine on // Wait until propagation delay period after block we plan to mine on
onDone, injectNulls, err = m.waitFunc(ctx, prebase.TipSet.MinTimestamp()) onDone, injectNulls, err = m.waitFunc(ctx, prebase.TipSet.MinTimestamp())