feat(workflow): record steps skipped by when as skipped
This commit is contained in:
1 parent
320b9dc340
commit
0598a357dd
15 files changed
+93
-25
No files matched your search
@@ -16,6 +16,9 @@ const (
|
||||
StepFailed StepStatus = "failed"
|
||||
StepCancelled StepStatus = "cancelled"
|
||||
StepInterrupted StepStatus = "interrupted"
|
||||
// StepSkipped is a step whose when condition was false: it never ran, but
|
||||
// it is still a step of the attempt and is recorded as one.
|
||||
StepSkipped StepStatus = "skipped"
|
||||
)
|
||||
|
||||
// executionTransitions lists every legal execution status move. Terminal
|
||||
@@ -38,12 +41,13 @@ var executionTransitions = map[string][]string{
|
||||
// vocabulary.
|
||||
var stepTransitions = map[StepStatus][]StepStatus{
|
||||
StepPending: {StepRunning, StepCancelled},
|
||||
StepRunning: {StepSucceeded, StepFailed, StepCancelled, StepInterrupted},
|
||||
StepRunning: {StepSucceeded, StepFailed, StepCancelled, StepInterrupted, StepSkipped},
|
||||
|
||||
StepSucceeded: nil,
|
||||
StepFailed: nil,
|
||||
StepCancelled: nil,
|
||||
StepInterrupted: nil,
|
||||
StepSkipped: nil,
|
||||
}
|
||||
|
||||
// CanTransition reports whether a WorkflowExecution may move from one status to
|
||||
@@ -63,7 +67,7 @@ func CanStepTransition(from, to StepStatus) bool {
|
||||
// only moves again as a fresh step in a new attempt.
|
||||
func StepTerminal(status StepStatus) bool {
|
||||
switch status {
|
||||
case StepSucceeded, StepFailed, StepCancelled, StepInterrupted:
|
||||
case StepSucceeded, StepFailed, StepCancelled, StepInterrupted, StepSkipped:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package taskstate
|
||||
|
||||
import "testing"
|
||||
|
||||
// The step guard is the store's own enforcement of which step moves are legal.
|
||||
// A skipped step is a running step's outcome and a terminal state: one that
|
||||
// never started cannot skip, and one that skipped never moves again.
|
||||
func TestStepTransitions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
from, to StepStatus
|
||||
want bool
|
||||
}{
|
||||
{"a running step is skipped", StepRunning, StepSkipped, true},
|
||||
{"a running step still succeeds", StepRunning, StepSucceeded, true},
|
||||
{"a pending step is not skipped", StepPending, StepSkipped, false},
|
||||
{"a skipped step does not move", StepSkipped, StepRunning, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := CanStepTransition(tt.from, tt.to); got != tt.want {
|
||||
t.Fatalf("CanStepTransition(%s, %s) = %v, want %v", tt.from, tt.to, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user