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{})
minedTwo := make(chan struct{})
m2addr, err := sn[1].ActorAddress(context.TODO())
if err != nil {
t.Fatal(err)
}
go func() {
doneMinedTwo := false
defer close(done)
prevExpect := 0
for atomic.LoadInt32(&mine) != 0 {
wait := make(chan int, 2)
wait := make(chan int)
mdone := func(mined bool, err error) {
go func() {
n := 0
if mined {
n = 1
}
wait <- n
}()
}
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
}
for {
n := 0
for i, node := range sn {
var nodeOneMined bool
for _, node := range sn {
mb, err := node.MiningBase(ctx)
if err != nil {
t.Error(err)
return
}
if len(mb.Cids()) != expect {
log.Warnf("node %d mining base not complete (%d, want %d)", i, len(mb.Cids()), expect)
continue
}
n++
}
if n == len(sn) {
for _, b := range mb.Blocks() {
if b.Miner == m2addr {
nodeOneMined = true
break
}
time.Sleep(blocktime)
}
if prevExpect == 2 && expect == 2 && !doneMinedTwo {
}
if nodeOneMined {
close(minedTwo)
doneMinedTwo = true
}
prevExpect = expect
}
}()

View File

@ -6,10 +6,11 @@ import (
"crypto/rand"
"encoding/binary"
"fmt"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"sync"
"time"
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"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 {
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
onDone, injectNulls, err = m.waitFunc(ctx, prebase.TipSet.MinTimestamp())