Files
sam e75d5c8ade
deploy / plan (push) Successful in 7s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 4m4s
fix(store): a restart re-queues a running task at its interrupted step and parks it after 3 restarts (#1841)
2026-11-09 14:36:08 +11:00

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)
}
})
}
}