38 lines
1.5 KiB
Go
38 lines
1.5 KiB
Go
package taskstate
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTransientParkRetry(t *testing.T) {
|
|
parked := time.Date(2026, 11, 8, 0, 0, 0, 0, time.UTC)
|
|
tests := []struct {
|
|
name string
|
|
class string
|
|
retries int
|
|
wait time.Duration
|
|
wantDue bool
|
|
wantClass ParkClass
|
|
}{
|
|
{"fresh park waits out the backoff", ParkTransient, 0, 10 * time.Second, false, ParkTransient},
|
|
{"first retry after the base wait", ParkTransient, 0, 30 * time.Second, true, ParkTransient},
|
|
{"backoff doubles", ParkTransient, 2, 119 * time.Second, false, ParkTransient},
|
|
{"backoff doubles, due", ParkTransient, 2, 120 * time.Second, true, ParkTransient},
|
|
{"last allowed retry", ParkTransient, MaxTransientRetries - 1, 24 * time.Hour, true, ParkTransient},
|
|
{"exhausted park escalates and is never retried", ParkTransient, MaxTransientRetries, 24 * time.Hour, false, ParkNeedsDecision},
|
|
{"needs_decision is never retried", ParkNeedsDecision, 0, 24 * time.Hour, false, ParkNeedsDecision},
|
|
{"terminal is never retried or escalated", ParkTerminal, MaxTransientRetries, 24 * time.Hour, false, ParkTerminal},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := TransientRetryDue(tt.class, tt.retries, parked, parked.Add(tt.wait)); got != tt.wantDue {
|
|
t.Errorf("TransientRetryDue = %v, want %v", got, tt.wantDue)
|
|
}
|
|
if got := ParkClassFor(tt.class, tt.retries); got != tt.wantClass {
|
|
t.Errorf("ParkClassFor = %q, want %q", got, tt.wantClass)
|
|
}
|
|
})
|
|
}
|
|
}
|