Skip to content

Commit

Permalink
sealing pipeline: Test clearing CreationTime
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Nov 14, 2022
1 parent d8c1b67 commit 97d4599
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions storage/pipeline/fsm_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func (evt SectorRevertUpgradeToProving) apply(state *SectorInfo) {
state.ReplicaUpdateMessage = nil
state.Pieces = state.CCPieces
state.CCPieces = nil
state.CreationTime = 0
}

type SectorRetrySubmitReplicaUpdateWait struct{}
Expand Down
64 changes: 62 additions & 2 deletions storage/pipeline/fsm_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package sealing

import (
"testing"

logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/require"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -390,3 +389,64 @@ func TestTicketExpired(t *testing.T) {
}
}
}

func TestCreationTimeCleared(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]SectorState{},
byState: map[SectorState]int64{},
},
notifee: func(before, after SectorInfo) {
notif = append(notif, struct{ before, after SectorInfo }{before, after})
},
},
t: t,
state: &SectorInfo{State: Available},
}

// sector starts with zero CreationTime
m.planSingle(SectorStartCCUpdate{})
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)

require.Equal(t, int64(0), m.state.CreationTime)

// First AddPiece will set CreationTime
m.planSingle(SectorAddPiece{})
require.Equal(m.t, m.state.State, SnapDealsAddPiece)

require.NotEqual(t, int64(0), m.state.CreationTime)

m.planSingle(SectorPieceAdded{})
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)

// abort shoult clean up CreationTime
m.planSingle(SectorAbortUpgrade{})
require.Equal(m.t, m.state.State, AbortUpgrade)

require.NotEqual(t, int64(0), m.state.CreationTime)

m.planSingle(SectorRevertUpgradeToProving{})
require.Equal(m.t, m.state.State, Proving)

require.Equal(t, int64(0), m.state.CreationTime)

m.planSingle(SectorMarkForUpdate{})

// in case CreationTime was set for whatever reason (lotus bug / manual sector state change)
// make sure we clean it up when starting upgrade
m.state.CreationTime = 325
m.planSingle(SectorStartCCUpdate{})
require.Equal(m.t, m.state.State, SnapDealsWaitDeals)

require.Equal(t, int64(0), m.state.CreationTime)

// "First" AddPiece will set CreationTime
m.planSingle(SectorAddPiece{})
require.Equal(m.t, m.state.State, SnapDealsAddPiece)

require.NotEqual(t, int64(0), m.state.CreationTime)
}

0 comments on commit 97d4599

Please sign in to comment.