49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package taskstate
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestPlanRecovery(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
give RecoveryInput
|
|
want Recovery
|
|
}{
|
|
{
|
|
name: "resumes at the interrupted step with the finished steps' results",
|
|
give: RecoveryInput{Stage: "build", PriorResults: []byte(`{"plan":1}`)},
|
|
want: Recovery{RetryMode: string(RetryKeepWorktree), ResumeFrom: "build", ResumeResults: []byte(`{"plan":1}`)},
|
|
},
|
|
{
|
|
name: "a crash inside the first resumed step keeps the row's resume point",
|
|
give: RecoveryInput{Stage: "build", ResumeFrom: "build", ResumeResults: []byte(`{"plan":1}`)},
|
|
want: Recovery{RetryMode: string(RetryKeepWorktree), ResumeFrom: "build", ResumeResults: []byte(`{"plan":1}`)},
|
|
},
|
|
{
|
|
name: "the first step of a fresh attempt starts over",
|
|
give: RecoveryInput{Stage: "plan", RetryMode: string(RetryContinuePushedWork), ResumeResults: []byte(`{}`)},
|
|
want: Recovery{RetryMode: string(RetryContinuePushedWork), ResumeResults: []byte(`{}`)},
|
|
},
|
|
{
|
|
name: "no running step leaves the row as it is",
|
|
give: RecoveryInput{ResumeResults: []byte(`{}`)},
|
|
want: Recovery{ResumeResults: []byte(`{}`)},
|
|
},
|
|
{
|
|
name: "parks once the cap is spent",
|
|
give: RecoveryInput{Restarts: MaxRestartRequeues, Stage: "build", PriorResults: []byte(`{}`)},
|
|
want: Recovery{Park: true, ParkReason: "interrupted by 3 daemon restarts in a row; retry to run it again"},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := PlanRecovery(tt.give)
|
|
if got.Park != tt.want.Park || got.ParkReason != tt.want.ParkReason || got.RetryMode != tt.want.RetryMode ||
|
|
got.ResumeFrom != tt.want.ResumeFrom || string(got.ResumeResults) != string(tt.want.ResumeResults) {
|
|
t.Errorf("PlanRecovery() = %+v, want %+v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|