refactor: sector terminate test to kit2

This commit is contained in:
Dirk McCormick 2021-06-17 10:40:41 +02:00
parent 8f608dff45
commit 6567887e6e
4 changed files with 42 additions and 83 deletions

21
itests/kit2/chain.go Normal file
View File

@ -0,0 +1,21 @@
package kit2
import (
"context"
"testing"
"time"
"github.com/filecoin-project/go-state-types/abi"
"github.com/stretchr/testify/require"
)
func WaitTillChainHeight(ctx context.Context, t *testing.T, node *TestFullNode, blocktime time.Duration, height int) abi.ChainEpoch {
for {
h, err := node.ChainHead(ctx)
require.NoError(t, err)
if h.Height() > abi.ChainEpoch(height) {
return h.Height()
}
time.Sleep(blocktime)
}
}

View File

@ -23,7 +23,7 @@ type ensembleOpts struct {
} }
var DefaultEnsembleOpts = ensembleOpts{ var DefaultEnsembleOpts = ensembleOpts{
pastOffset: 100000 * time.Second, // time sufficiently in the past to trigger catch-up mining. pastOffset: 10000000 * time.Second, // time sufficiently in the past to trigger catch-up mining.
proofType: abi.RegisteredSealProof_StackedDrg2KiBV1, proofType: abi.RegisteredSealProof_StackedDrg2KiBV1,
} }

View File

@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing" sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
@ -60,7 +58,7 @@ func TestPledgeBatching(t *testing.T) {
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts) client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
ens.InterconnectAll().BeginMining(blockTime) ens.InterconnectAll().BeginMining(blockTime)
waitTillChainHeight(ctx, t, client, 10) kit2.WaitTillChainHeight(ctx, t, client, blockTime, 10)
toCheck := miner.StartPledge(ctx, nSectors, 0, nil) toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
@ -117,7 +115,7 @@ func TestPledgeBeforeNv13(t *testing.T) {
client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts) client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
ens.InterconnectAll().BeginMining(blocktime) ens.InterconnectAll().BeginMining(blocktime)
waitTillChainHeight(ctx, t, client, 10) kit2.WaitTillChainHeight(ctx, t, client, blocktime, 10)
toCheck := miner.StartPledge(ctx, nSectors, 0, nil) toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
@ -145,13 +143,3 @@ func TestPledgeBeforeNv13(t *testing.T) {
runTest(t, 100) runTest(t, 100)
}) })
} }
func waitTillChainHeight(ctx context.Context, t *testing.T, node *kit2.TestFullNode, height int) {
for {
h, err := node.ChainHead(ctx)
require.NoError(t, err)
if h.Height() > abi.ChainEpoch(height) {
return
}
}
}

View File

@ -2,18 +2,15 @@ package itests
import ( import (
"context" "context"
"fmt"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
sealing "github.com/filecoin-project/lotus/extern/storage-sealing" sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
"github.com/filecoin-project/lotus/itests/kit" "github.com/filecoin-project/lotus/itests/kit2"
"github.com/filecoin-project/lotus/node/impl"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -22,7 +19,7 @@ func TestTerminate(t *testing.T) {
t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run") t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run")
} }
kit.QuietMiningLogs() kit2.QuietMiningLogs()
const blocktime = 2 * time.Millisecond const blocktime = 2 * time.Millisecond
@ -31,42 +28,9 @@ func TestTerminate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
n, sn := kit.MockMinerBuilder(t, opts := kit2.ConstructorOpts(kit2.LatestActorsAt(-1))
[]kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(-1)}, client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
[]kit.StorageMiner{{Full: 0, Preseal: int(nSectors)}}, ens.InterconnectAll().BeginMining(blocktime)
)
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
addrinfo, err := client.NetAddrsListen(ctx)
if err != nil {
t.Fatal(err)
}
if err := miner.NetConnect(ctx, addrinfo); err != nil {
t.Fatal(err)
}
build.Clock.Sleep(time.Second)
done := make(chan struct{})
go func() {
defer close(done)
for ctx.Err() == nil {
build.Clock.Sleep(blocktime)
if err := sn[0].MineOne(ctx, kit.MineNext); err != nil {
if ctx.Err() != nil {
// context was canceled, ignore the error.
return
}
t.Error(err)
}
}
}()
defer func() {
cancel()
<-done
}()
maddr, err := miner.ActorAddress(ctx) maddr, err := miner.ActorAddress(ctx)
require.NoError(t, err) require.NoError(t, err)
@ -79,11 +43,11 @@ func TestTerminate(t *testing.T) {
require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, p.MinerPower, p.TotalPower)
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors)) require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors))
fmt.Printf("Seal a sector\n") t.Log("Seal a sector")
kit.PledgeSectors(t, ctx, miner, 1, 0, nil) miner.PledgeSectors(ctx, 1, 0, nil)
fmt.Printf("wait for power\n") t.Log("wait for power")
{ {
// Wait until proven. // Wait until proven.
@ -91,17 +55,10 @@ func TestTerminate(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2 waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
fmt.Printf("End for head.Height > %d\n", waitUntil) t.Logf("End for head.Height > %d", waitUntil)
for { height := kit2.WaitTillChainHeight(ctx, t, client, blocktime, int(waitUntil))
head, err := client.ChainHead(ctx) t.Logf("Now head.Height = %d", height)
require.NoError(t, err)
if head.Height() > waitUntil {
fmt.Printf("Now head.Height = %d\n", head.Height())
break
}
}
} }
nSectors++ nSectors++
@ -111,7 +68,7 @@ func TestTerminate(t *testing.T) {
require.Equal(t, p.MinerPower, p.TotalPower) require.Equal(t, p.MinerPower, p.TotalPower)
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors)) require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors))
fmt.Println("Terminate a sector") t.Log("Terminate a sector")
toTerminate := abi.SectorNumber(3) toTerminate := abi.SectorNumber(3)
@ -124,7 +81,7 @@ loop:
si, err := miner.SectorsStatus(ctx, toTerminate, false) si, err := miner.SectorsStatus(ctx, toTerminate, false)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("state: ", si.State, msgTriggerred) t.Log("state: ", si.State, msgTriggerred)
switch sealing.SectorState(si.State) { switch sealing.SectorState(si.State) {
case sealing.Terminating: case sealing.Terminating:
@ -140,7 +97,7 @@ loop:
require.NoError(t, err) require.NoError(t, err)
if c != nil { if c != nil {
msgTriggerred = true msgTriggerred = true
fmt.Println("terminate message:", c) t.Log("terminate message:", c)
{ {
p, err := miner.SectorTerminatePending(ctx) p, err := miner.SectorTerminatePending(ctx)
@ -180,18 +137,11 @@ loop:
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK) di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
require.NoError(t, err) require.NoError(t, err)
for {
head, err := client.ChainHead(ctx)
require.NoError(t, err)
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod+2 { waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
fmt.Printf("Now head.Height = %d\n", head.Height()) t.Logf("End for head.Height > %d", waitUntil)
break height := kit2.WaitTillChainHeight(ctx, t, client, blocktime, int(waitUntil))
} t.Logf("Now head.Height = %d", height)
build.Clock.Sleep(blocktime)
}
require.NoError(t, err)
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod+2)
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK) p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
require.NoError(t, err) require.NoError(t, err)