storagefsm: Test applying global events in broken state

This commit is contained in:
Łukasz Magiera 2021-04-06 15:38:13 +02:00
parent 9a2ec07837
commit 9fb345af67

View File

@ -175,3 +175,38 @@ func TestPlannerList(t *testing.T) {
require.True(t, ok, "state %s", state)
}
}
func TestBrokenState(t *testing.T) {
var notif []struct{ before, after SectorInfo }
ma, _ := address.NewIDAddress(55151)
m := test{
s: &Sealing{
maddr: ma,
stats: SectorStats{
bySector: map[abi.SectorID]statSectorState{},
},
notifee: func(before, after SectorInfo) {
notif = append(notif, struct{ before, after SectorInfo }{before, after})
},
},
t: t,
state: &SectorInfo{State: "not a state"},
}
_, _, err := m.s.plan([]statemachine.Event{{User: SectorPacked{}}}, m.state)
require.Error(t, err)
require.Equal(m.t, m.state.State, SectorState("not a state"))
m.planSingle(SectorRemove{})
require.Equal(m.t, m.state.State, Removing)
expected := []SectorState{"not a state", "not a state", Removing}
for i, n := range notif {
if n.before.State != expected[i] {
t.Fatalf("expected before state: %s, got: %s", expected[i], n.before.State)
}
if n.after.State != expected[i+1] {
t.Fatalf("expected after state: %s, got: %s", expected[i+1], n.after.State)
}
}
}