improve flakiness of a few tests
This commit is contained in:
parent
14cda27e9f
commit
d0585ca7bb
@ -39,7 +39,7 @@ func (ts *testSuite) testMining(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, abi.ChainEpoch(2), h1.Height())
|
||||
|
||||
err = sn[0].MineOne(ctx, MineNext)
|
||||
MineUntilBlock(ctx, t, sn[0], nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
<-newHeads
|
||||
@ -70,7 +70,7 @@ func (ts *testSuite) testMiningReal(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, abi.ChainEpoch(2), h1.Height())
|
||||
|
||||
err = sn[0].MineOne(ctx, MineNext)
|
||||
MineUntilBlock(ctx, t, sn[0], nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
<-newHeads
|
||||
@ -79,7 +79,7 @@ func (ts *testSuite) testMiningReal(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, abi.ChainEpoch(3), h2.Height())
|
||||
|
||||
err = sn[0].MineOne(ctx, MineNext)
|
||||
MineUntilBlock(ctx, t, sn[0], nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
<-newHeads
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/miner"
|
||||
)
|
||||
|
||||
func SendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address.Address, amount abi.TokenAmount) {
|
||||
@ -34,3 +35,30 @@ func SendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address.
|
||||
t.Fatal("did not successfully send money")
|
||||
}
|
||||
}
|
||||
|
||||
func MineUntilBlock(ctx context.Context, t *testing.T, sn TestStorageNode, cb func()) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
var success bool
|
||||
var err error
|
||||
wait := make(chan struct{})
|
||||
sn.MineOne(ctx, miner.MineReq{
|
||||
Done: func(win bool, e error) {
|
||||
success = win
|
||||
err = e
|
||||
wait <- struct{}{}
|
||||
},
|
||||
})
|
||||
<-wait
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if success {
|
||||
if cb != nil {
|
||||
cb()
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Log("did not mine block, trying again", i)
|
||||
}
|
||||
t.Fatal("failed to mine 1000 times in a row...")
|
||||
}
|
||||
|
@ -270,13 +270,13 @@ func Builder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestN
|
||||
var wait sync.Mutex
|
||||
wait.Lock()
|
||||
|
||||
_ = storers[0].MineOne(ctx, miner2.MineReq{Done: func(bool, error) {
|
||||
test.MineUntilBlock(ctx, t, storers[0], func() {
|
||||
wait.Unlock()
|
||||
}})
|
||||
})
|
||||
wait.Lock()
|
||||
_ = storers[0].MineOne(ctx, miner2.MineReq{Done: func(bool, error) {
|
||||
test.MineUntilBlock(ctx, t, storers[0], func() {
|
||||
wait.Unlock()
|
||||
}})
|
||||
})
|
||||
wait.Lock()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user