lotus/storage/sealing/fsm_test.go

107 lines
2.6 KiB
Go
Raw Normal View History

package sealing
2020-01-15 20:04:02 +00:00
import (
"testing"
logging "github.com/ipfs/go-log/v2"
2020-01-15 20:04:02 +00:00
"github.com/stretchr/testify/require"
2020-03-06 18:59:08 +00:00
"github.com/filecoin-project/go-statemachine"
2020-01-15 20:04:02 +00:00
"github.com/filecoin-project/lotus/api"
)
func init() {
_ = logging.SetLogLevel("*", "INFO")
}
2020-01-15 20:04:02 +00:00
func (t *test) planSingle(evt interface{}) {
2020-01-15 20:53:14 +00:00
_, err := t.s.plan([]statemachine.Event{{evt}}, t.state)
2020-01-15 20:04:02 +00:00
require.NoError(t.t, err)
}
type test struct {
2020-01-15 20:53:14 +00:00
s *Sealing
2020-01-15 20:04:02 +00:00
t *testing.T
state *SectorInfo
next func(statemachine.Context, SectorInfo) error
}
func TestHappyPath(t *testing.T) {
m := test{
2020-01-15 20:53:14 +00:00
s: &Sealing{},
2020-01-15 20:04:02 +00:00
t: t,
state: &SectorInfo{State: api.Packing},
}
m.planSingle(SectorPacked{})
require.Equal(m.t, m.state.State, api.Unsealed)
m.planSingle(SectorSealed{})
require.Equal(m.t, m.state.State, api.PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-01-20 22:04:46 +00:00
require.Equal(m.t, m.state.State, api.WaitSeed)
2020-01-15 20:04:02 +00:00
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing)
m.planSingle(SectorCommitted{})
require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{})
2020-01-31 01:27:38 +00:00
require.Equal(m.t, m.state.State, api.FinalizeSector)
m.planSingle(SectorFinalized{})
2020-01-15 20:04:02 +00:00
require.Equal(m.t, m.state.State, api.Proving)
}
func TestSeedRevert(t *testing.T) {
m := test{
2020-01-15 20:53:14 +00:00
s: &Sealing{},
2020-01-15 20:04:02 +00:00
t: t,
state: &SectorInfo{State: api.Packing},
}
m.planSingle(SectorPacked{})
require.Equal(m.t, m.state.State, api.Unsealed)
m.planSingle(SectorSealed{})
require.Equal(m.t, m.state.State, api.PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-01-20 22:04:46 +00:00
require.Equal(m.t, m.state.State, api.WaitSeed)
2020-01-15 20:04:02 +00:00
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing)
2020-02-27 21:45:31 +00:00
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
2020-01-15 20:04:02 +00:00
require.NoError(t, err)
require.Equal(m.t, m.state.State, api.Committing)
// not changing the seed this time
2020-02-27 21:45:31 +00:00
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
2020-01-15 20:04:02 +00:00
require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{})
2020-01-31 01:27:38 +00:00
require.Equal(m.t, m.state.State, api.FinalizeSector)
m.planSingle(SectorFinalized{})
2020-01-15 20:04:02 +00:00
require.Equal(m.t, m.state.State, api.Proving)
}
func TestPlanCommittingHandlesSectorCommitFailed(t *testing.T) {
m := test{
s: &Sealing{},
t: t,
state: &SectorInfo{State: api.Committing},
}
events := []statemachine.Event{{SectorCommitFailed{}}}
require.NoError(t, planCommitting(events, m.state))
require.Equal(t, api.SectorStates[api.CommitFailed], api.SectorStates[m.state.State])
}