Skip to content

Commit

Permalink
fix: test: flaky TestDeadlineToggling
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Sep 22, 2022
1 parent 7a2bc47 commit ac9adcb
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions itests/deadlines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestDeadlineToggling(t *testing.T) {
build.Clock.Sleep(blocktime)
}

checkMiner := func(ma address.Address, power abi.StoragePower, active, activeIfCron bool, tsk types.TipSetKey) {
checkMiner := func(ma address.Address, power abi.StoragePower, active bool, tsk types.TipSetKey) {
//stm: @CHAIN_STATE_MINER_POWER_001
p, err := client.StateMinerPower(ctx, ma, tsk)
require.NoError(t, err)
Expand All @@ -178,21 +178,6 @@ func TestDeadlineToggling(t *testing.T) {
act, err := mst.DeadlineCronActive()
require.NoError(t, err)

if tsk != types.EmptyTSK {
ts, err := client.ChainGetTipSet(ctx, tsk)
require.NoError(t, err)
di, err := mst.DeadlineInfo(ts.Height())
require.NoError(t, err)

// cron happened on the same epoch some other condition would have happened
if di.Open <= ts.Height() {
act, err := mst.DeadlineCronActive()
require.NoError(t, err)
require.Equal(t, activeIfCron, act)
return
}
}

require.Equal(t, active, act)
}

Expand All @@ -218,19 +203,19 @@ func TestDeadlineToggling(t *testing.T) {
require.NoError(t, err)

// first round of miner checks
checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(uint64(ssz)*sectorsC), true, true, types.EmptyTSK)
checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(uint64(ssz)*sectorsC), true, types.EmptyTSK)

checkMiner(maddrB, types.NewInt(0), false, false, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(0), false, false, types.EmptyTSK)
checkMiner(maddrE, types.NewInt(0), false, false, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(0), false, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(0), false, types.EmptyTSK)
checkMiner(maddrE, types.NewInt(0), false, types.EmptyTSK)

// pledge sectors on minerB/minerD, stop post on minerC
minerB.PledgeSectors(ctx, sectorsB, 0, nil)
checkMiner(maddrB, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(0), true, types.EmptyTSK)

minerD.PledgeSectors(ctx, sectorsD, 0, nil)
checkMiner(maddrD, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(0), true, types.EmptyTSK)

minerC.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).Fail()

Expand Down Expand Up @@ -281,7 +266,7 @@ func TestDeadlineToggling(t *testing.T) {
build.Clock.Sleep(blocktime)
}

checkMiner(maddrE, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrE, types.NewInt(0), true, types.EmptyTSK)

// go through rest of the PP
for {
Expand All @@ -296,11 +281,11 @@ func TestDeadlineToggling(t *testing.T) {
}

// second round of miner checks
checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(uint64(ssz)*sectorsB), true, true, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(uint64(ssz)*sectorsD), true, true, types.EmptyTSK)
checkMiner(maddrE, types.NewInt(0), false, false, types.EmptyTSK)
checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(0), true, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(uint64(ssz)*sectorsB), true, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(uint64(ssz)*sectorsD), true, types.EmptyTSK)
checkMiner(maddrE, types.NewInt(0), false, types.EmptyTSK)

// disable post on minerB
minerB.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).Fail()
Expand Down Expand Up @@ -353,8 +338,10 @@ func TestDeadlineToggling(t *testing.T) {
require.NoError(t, err)
require.Equal(t, exitcode.Ok, r.Receipt.ExitCode)

// assert inactive if the message landed in the tipset we run cron in
checkMiner(maddrD, types.NewInt(0), true, false, r.TipSet)
// assert miner has no power
p, err := client.StateMinerPower(ctx, maddrD, r.TipSet)
require.NoError(t, err)
require.True(t, p.MinerPower.RawBytePower.IsZero())
}

// go through another PP
Expand All @@ -369,8 +356,8 @@ func TestDeadlineToggling(t *testing.T) {
build.Clock.Sleep(blocktime)
}

checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(0), true, true, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(0), false, false, types.EmptyTSK)
checkMiner(maddrA, types.NewInt(uint64(ssz)*kit.DefaultPresealsPerBootstrapMiner), true, types.EmptyTSK)
checkMiner(maddrC, types.NewInt(0), true, types.EmptyTSK)
checkMiner(maddrB, types.NewInt(0), true, types.EmptyTSK)
checkMiner(maddrD, types.NewInt(0), false, types.EmptyTSK)
}

0 comments on commit ac9adcb

Please sign in to comment.