package store import ( "context" "strings" "testing" "time" ) func TestExpireStalledAllocationsSQLFencesAndRequeuesWithoutPenalty(t *testing.T) { for _, fragment := range []string{ "ALLOCATING", "PROCESS_READY", "ASSIGNMENT_READY", "FOR UPDATE SKIP LOCKED", "SET state = 'FAILED'", "SET participation_active = FALSE", "SET state = 'QUEUED'", "INSERT INTO outbox", "'state_changed'", "'stalled-allocation:'", } { if !strings.Contains(ExpireStalledAllocationsSQL, fragment) { t.Fatalf("ExpireStalledAllocationsSQL missing fragment %q:\n%s", fragment, ExpireStalledAllocationsSQL) } } if !strings.Contains(ExpireStalledAllocationsSQL, "occurred_at', $4") { t.Fatalf("stalled allocation event timestamp is not bound") } } func TestExpireStalledAllocationsRejectsInvalidArgumentsWithoutDatabase(t *testing.T) { now := time.Unix(1000, 0).UTC() if _, err := ExpireStalledAllocations(context.Background(), nil, now, time.Minute, 10); err == nil { t.Fatal("nil database accepted") } if _, err := ExpireStalledAllocations(context.Background(), nil, time.Time{}, time.Minute, 10); err == nil { t.Fatal("zero time accepted") } if _, err := ExpireStalledAllocations(context.Background(), nil, now, 0, 10); err == nil { t.Fatal("non-positive deadline accepted") } if _, err := ExpireStalledAllocations(context.Background(), nil, now, time.Minute, 0); err == nil { t.Fatal("zero limit accepted") } if _, err := ExpireStalledAllocations(context.Background(), nil, now, time.Minute, 1001); err == nil { t.Fatal("oversized limit accepted") } }