lotus/extern/storage-sealing/fsm_test.go

143 lines
3.5 KiB
Go
Raw Normal View History

package sealing
import (
"testing"
2020-08-18 16:27:18 +00:00
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
2020-03-06 18:59:08 +00:00
"github.com/filecoin-project/go-statemachine"
)
func init() {
_ = logging.SetLogLevel("*", "INFO")
}
func (t *test) planSingle(evt interface{}) {
2020-08-27 19:34:45 +00:00
_, _, err := t.s.plan([]statemachine.Event{{User: evt}}, t.state)
require.NoError(t.t, err)
}
type test struct {
2020-01-15 20:53:14 +00:00
s *Sealing
t *testing.T
state *SectorInfo
}
func TestHappyPath(t *testing.T) {
2020-08-18 16:27:18 +00:00
ma, _ := address.NewIDAddress(55151)
m := test{
2020-08-18 16:27:18 +00:00
s: &Sealing{
maddr: ma,
stats: SectorStats{
bySector: map[abi.SectorID]statSectorState{},
},
},
t: t,
state: &SectorInfo{State: Packing},
}
m.planSingle(SectorPacked{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommit1)
m.planSingle(SectorPreCommit1{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommit2)
2020-04-03 16:54:01 +00:00
m.planSingle(SectorPreCommit2{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-05-18 22:49:21 +00:00
require.Equal(m.t, m.state.State, PreCommitWait)
m.planSingle(SectorPreCommitLanded{})
require.Equal(m.t, m.state.State, WaitSeed)
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, Committing)
m.planSingle(SectorCommitted{})
require.Equal(m.t, m.state.State, SubmitCommit)
m.planSingle(SectorCommitSubmitted{})
require.Equal(m.t, m.state.State, CommitWait)
m.planSingle(SectorProving{})
require.Equal(m.t, m.state.State, FinalizeSector)
2020-01-31 01:27:38 +00:00
m.planSingle(SectorFinalized{})
require.Equal(m.t, m.state.State, Proving)
}
func TestSeedRevert(t *testing.T) {
2020-08-18 16:27:18 +00:00
ma, _ := address.NewIDAddress(55151)
m := test{
2020-08-18 16:27:28 +00:00
s: &Sealing{
maddr: ma,
stats: SectorStats{
bySector: map[abi.SectorID]statSectorState{},
},
},
t: t,
state: &SectorInfo{State: Packing},
}
m.planSingle(SectorPacked{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommit1)
m.planSingle(SectorPreCommit1{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommit2)
2020-04-03 16:54:01 +00:00
m.planSingle(SectorPreCommit2{})
2020-04-06 20:23:37 +00:00
require.Equal(m.t, m.state.State, PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-05-18 22:49:21 +00:00
require.Equal(m.t, m.state.State, PreCommitWait)
m.planSingle(SectorPreCommitLanded{})
require.Equal(m.t, m.state.State, WaitSeed)
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, Committing)
2020-08-27 19:34:45 +00:00
_, _, err := m.s.plan([]statemachine.Event{{User: SectorSeedReady{SeedValue: nil, SeedEpoch: 5}}, {User: SectorCommitted{}}}, m.state)
require.NoError(t, err)
require.Equal(m.t, m.state.State, Committing)
// not changing the seed this time
2020-08-27 19:34:45 +00:00
_, _, err = m.s.plan([]statemachine.Event{{User: SectorSeedReady{SeedValue: nil, SeedEpoch: 5}}, {User: SectorCommitted{}}}, m.state)
require.NoError(t, err)
require.Equal(m.t, m.state.State, SubmitCommit)
m.planSingle(SectorCommitSubmitted{})
require.Equal(m.t, m.state.State, CommitWait)
m.planSingle(SectorProving{})
require.Equal(m.t, m.state.State, FinalizeSector)
2020-01-31 01:27:38 +00:00
m.planSingle(SectorFinalized{})
require.Equal(m.t, m.state.State, Proving)
}
func TestPlanCommittingHandlesSectorCommitFailed(t *testing.T) {
2020-08-18 16:27:18 +00:00
ma, _ := address.NewIDAddress(55151)
m := test{
2020-08-18 16:27:28 +00:00
s: &Sealing{
maddr: ma,
stats: SectorStats{
bySector: map[abi.SectorID]statSectorState{},
},
},
t: t,
state: &SectorInfo{State: Committing},
}
events := []statemachine.Event{{User: SectorCommitFailed{}}}
2020-08-27 19:34:45 +00:00
_, err := planCommitting(events, m.state)
require.NoError(t, err)
2020-04-06 20:23:37 +00:00
require.Equal(t, CommitFailed, m.state.State)
}