-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"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/build" | ||
"github.com/filecoin-project/lotus/chain/stmgr" | ||
sealing "github.com/filecoin-project/lotus/extern/storage-sealing" | ||
"github.com/filecoin-project/lotus/node" | ||
"github.com/filecoin-project/lotus/node/impl" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTapeFix(t *testing.T, b APIBuilder, blocktime time.Duration) { | ||
t.Run("before", func(t *testing.T) { testTapeFix(t, b, blocktime, false) }) | ||
t.Run("after", func(t *testing.T) { testTapeFix(t, b, blocktime, true) }) | ||
} | ||
func testTapeFix(t *testing.T, b APIBuilder, blocktime time.Duration, after bool) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
upgradeSchedule := stmgr.UpgradeSchedule{{ | ||
Network: build.ActorUpgradeNetworkVersion, | ||
Height: 1, | ||
Migration: stmgr.UpgradeActorsV2, | ||
}} | ||
if after { | ||
upgradeSchedule = append(upgradeSchedule, stmgr.Upgrade{ | ||
Network: network.Version5, | ||
Height: 2, | ||
}) | ||
} | ||
|
||
n, sn := b(t, []FullNodeOpts{{Opts: func(_ []TestNode) node.Option { | ||
return node.Override(new(stmgr.UpgradeSchedule), upgradeSchedule) | ||
}}}, OneMiner) | ||
|
||
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, MineNext); err != nil { | ||
if ctx.Err() != nil { | ||
// context was canceled, ignore the error. | ||
return | ||
} | ||
t.Error(err) | ||
} | ||
} | ||
}() | ||
defer func() { | ||
cancel() | ||
<-done | ||
}() | ||
|
||
err = miner.PledgeSector(ctx) | ||
require.NoError(t, err) | ||
|
||
// Wait till done. | ||
var sectorNo abi.SectorNumber | ||
for { | ||
s, err := miner.SectorsList(ctx) // Note - the test builder doesn't import genesis sectors into FSM | ||
require.NoError(t, err) | ||
fmt.Printf("Sectors: %d\n", len(s)) | ||
if len(s) == 1 { | ||
sectorNo = s[0] | ||
break | ||
} | ||
|
||
build.Clock.Sleep(100 * time.Millisecond) | ||
} | ||
|
||
fmt.Printf("All sectors is fsm\n") | ||
|
||
// If before, we expect the precommit to fail | ||
successState := api.SectorState(sealing.CommitFailed) | ||
failureState := api.SectorState(sealing.Proving) | ||
if after { | ||
// otherwise, it should succeed. | ||
successState, failureState = failureState, successState | ||
} | ||
|
||
for { | ||
st, err := miner.SectorsStatus(ctx, sectorNo, false) | ||
require.NoError(t, err) | ||
if st.State == successState { | ||
break | ||
} | ||
require.NotEqual(t, failureState, st.State) | ||
build.Clock.Sleep(100 * time.Millisecond) | ||
fmt.Println("WaitSeal") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters