Merge pull request #6506 from filecoin-project/refactor/itest-sector-pledge

Refactor sector pledge test to use kit2
This commit is contained in:
raulk 2021-06-17 17:52:13 +01:00 committed by GitHub
commit 6562a23666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 149 deletions

View File

@ -58,10 +58,8 @@ func InstantaneousNetworkVersion(version network.Version) node.Option {
} }
func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option { func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option {
fullSchedule := stmgr.UpgradeSchedule{}
schedule := stmgr.UpgradeSchedule{} schedule := stmgr.UpgradeSchedule{}
for _, upgrade := range fullSchedule { for _, upgrade := range DefaultTestUpgradeSchedule {
if upgrade.Network > version { if upgrade.Network > version {
break break
} }

View File

@ -4,70 +4,40 @@ import (
"context" "context"
"fmt" "fmt"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/stmgr"
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"
bminer "github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
"github.com/stretchr/testify/require"
) )
func TestPledgeSectors(t *testing.T) { func TestPledgeSectors(t *testing.T) {
kit.QuietMiningLogs() kit2.QuietMiningLogs()
runTest := func(t *testing.T, b kit.APIBuilder, blocktime time.Duration, nSectors int) { blockTime := 50 * time.Millisecond
runTest := func(t *testing.T, nSectors int) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
n, sn := b(t, kit.OneFull, kit.OneMiner) _, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs())
client := n[0].FullNode.(*impl.FullNodeAPI) ens.InterconnectAll().BeginMining(blockTime)
miner := sn[0]
addrinfo, err := client.NetAddrsListen(ctx) miner.PledgeSectors(ctx, nSectors, 0, nil)
if err != nil {
t.Fatal(err)
}
if err := miner.NetConnect(ctx, addrinfo); err != nil {
t.Fatal(err)
}
build.Clock.Sleep(time.Second)
mine := int64(1)
done := make(chan struct{})
go func() {
defer close(done)
for atomic.LoadInt64(&mine) != 0 {
build.Clock.Sleep(blocktime)
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
}}); err != nil {
t.Error(err)
}
}
}()
kit.PledgeSectors(t, ctx, miner, nSectors, 0, nil)
atomic.StoreInt64(&mine, 0)
<-done
} }
t.Run("1", func(t *testing.T) { t.Run("1", func(t *testing.T) {
runTest(t, kit.MockMinerBuilder, 50*time.Millisecond, 1) runTest(t, 1)
}) })
t.Run("100", func(t *testing.T) { t.Run("100", func(t *testing.T) {
runTest(t, kit.MockMinerBuilder, 50*time.Millisecond, 100) runTest(t, 100)
}) })
t.Run("1000", func(t *testing.T) { t.Run("1000", func(t *testing.T) {
@ -75,52 +45,24 @@ func TestPledgeSectors(t *testing.T) {
t.Skip("skipping test in short mode") t.Skip("skipping test in short mode")
} }
runTest(t, kit.MockMinerBuilder, 50*time.Millisecond, 1000) runTest(t, 1000)
}) })
} }
func TestPledgeBatching(t *testing.T) { func TestPledgeBatching(t *testing.T) {
runTest := func(t *testing.T, b kit.APIBuilder, blocktime time.Duration, nSectors int) { blockTime := 50 * time.Millisecond
runTest := func(t *testing.T, nSectors int) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
n, sn := b(t, []kit.FullNodeOpts{kit.FullNodeWithLatestActorsAt(-1)}, kit.OneMiner) opts := kit2.ConstructorOpts(kit2.LatestActorsAt(-1))
client := n[0].FullNode.(*impl.FullNodeAPI) client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
miner := sn[0] ens.InterconnectAll().BeginMining(blockTime)
addrinfo, err := client.NetAddrsListen(ctx) waitTillChainHeight(ctx, t, client, 10)
if err != nil {
t.Fatal(err)
}
if err := miner.NetConnect(ctx, addrinfo); err != nil { toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
t.Fatal(err)
}
build.Clock.Sleep(time.Second)
mine := int64(1)
done := make(chan struct{})
go func() {
defer close(done)
for atomic.LoadInt64(&mine) != 0 {
build.Clock.Sleep(blocktime)
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
}}); err != nil {
t.Error(err)
}
}
}()
for {
h, err := client.ChainHead(ctx)
require.NoError(t, err)
if h.Height() > 10 {
break
}
}
toCheck := kit.StartPledge(t, ctx, miner, nSectors, 0, nil)
for len(toCheck) > 0 { for len(toCheck) > 0 {
states := map[api.SectorState]int{} states := map[api.SectorState]int{}
@ -157,80 +99,27 @@ func TestPledgeBatching(t *testing.T) {
build.Clock.Sleep(100 * time.Millisecond) build.Clock.Sleep(100 * time.Millisecond)
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states) fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
} }
atomic.StoreInt64(&mine, 0)
<-done
} }
t.Run("100", func(t *testing.T) { t.Run("100", func(t *testing.T) {
runTest(t, kit.MockMinerBuilder, 50*time.Millisecond, 100) runTest(t, 100)
}) })
} }
func TestPledgeBeforeNv13(t *testing.T) { func TestPledgeBeforeNv13(t *testing.T) {
runTest := func(t *testing.T, b kit.APIBuilder, blocktime time.Duration, nSectors int) { blocktime := 50 * time.Millisecond
runTest := func(t *testing.T, nSectors int) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
n, sn := b(t, []kit.FullNodeOpts{ opts := kit2.ConstructorOpts(kit2.LatestActorsAt(1000000000))
{ client, miner, ens := kit2.EnsembleMinimal(t, kit2.MockProofs(), opts)
Opts: func(nodes []kit.TestFullNode) node.Option { ens.InterconnectAll().BeginMining(blocktime)
return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{
Network: network.Version9,
Height: 1,
Migration: stmgr.UpgradeActorsV2,
}, {
Network: network.Version10,
Height: 2,
Migration: stmgr.UpgradeActorsV3,
}, {
Network: network.Version12,
Height: 3,
Migration: stmgr.UpgradeActorsV4,
}, {
Network: network.Version13,
Height: 1000000000,
Migration: stmgr.UpgradeActorsV5,
}})
},
},
}, kit.OneMiner)
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
addrinfo, err := client.NetAddrsListen(ctx) waitTillChainHeight(ctx, t, client, 10)
if err != nil {
t.Fatal(err)
}
if err := miner.NetConnect(ctx, addrinfo); err != nil { toCheck := miner.StartPledge(ctx, nSectors, 0, nil)
t.Fatal(err)
}
build.Clock.Sleep(time.Second)
mine := int64(1)
done := make(chan struct{})
go func() {
defer close(done)
for atomic.LoadInt64(&mine) != 0 {
build.Clock.Sleep(blocktime)
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
}}); err != nil {
t.Error(err)
}
}
}()
for {
h, err := client.ChainHead(ctx)
require.NoError(t, err)
if h.Height() > 10 {
break
}
}
toCheck := kit.StartPledge(t, ctx, miner, nSectors, 0, nil)
for len(toCheck) > 0 { for len(toCheck) > 0 {
states := map[api.SectorState]int{} states := map[api.SectorState]int{}
@ -250,12 +139,19 @@ func TestPledgeBeforeNv13(t *testing.T) {
build.Clock.Sleep(100 * time.Millisecond) build.Clock.Sleep(100 * time.Millisecond)
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states) fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
} }
atomic.StoreInt64(&mine, 0)
<-done
} }
t.Run("100-before-nv13", func(t *testing.T) { t.Run("100-before-nv13", func(t *testing.T) {
runTest(t, kit.MockMinerBuilder, 50*time.Millisecond, 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
}
}
}