This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSchedulerRunRetentionCutoffKeepsFifteenDays(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 22, 0, 0, 0, time.FixedZone("UTC+8", 8*60*60))
|
||||
|
||||
got := schedulerRunRetentionCutoff(now, defaultSchedulerRunRetentionDays)
|
||||
want := time.Date(2026, 5, 6, 0, 0, 0, 0, time.FixedZone("UTC+8", 8*60*60)).UTC()
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("cutoff = %s, want %s", got.Format(time.RFC3339), want.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchedulerRunRetentionCutoffHasHardFloor(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 22, 0, 0, 0, time.FixedZone("UTC+8", 8*60*60))
|
||||
|
||||
got := schedulerRunRetentionCutoff(now, 7)
|
||||
want := schedulerRunRetentionCutoff(now, defaultSchedulerRunRetentionDays)
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("cutoff = %s, want hard floor cutoff %s", got.Format(time.RFC3339), want.Format(time.RFC3339))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchedulerRunRetentionSQLIsBoundedAndFKSafe(t *testing.T) {
|
||||
triggerDeleteSQL := schedulerRunRetentionTriggerDeleteSQL()
|
||||
for _, want := range []string{
|
||||
"status IN ('success', 'failed', 'skipped')",
|
||||
"LIMIT $2",
|
||||
"FOR UPDATE SKIP LOCKED",
|
||||
"DELETE FROM ops.scheduler_job_triggers target",
|
||||
} {
|
||||
if !strings.Contains(triggerDeleteSQL, want) {
|
||||
t.Fatalf("trigger retention SQL missing %q in SQL:\n%s", want, triggerDeleteSQL)
|
||||
}
|
||||
}
|
||||
|
||||
runDeleteSQL := schedulerRunRetentionRunDeleteSQL()
|
||||
for _, want := range []string{
|
||||
"NOT EXISTS (SELECT 1 FROM ops.scheduler_job_triggers t WHERE t.run_id = r.id)",
|
||||
"LIMIT $2",
|
||||
"FOR UPDATE SKIP LOCKED",
|
||||
"DELETE FROM ops.scheduler_job_runs target",
|
||||
} {
|
||||
if !strings.Contains(runDeleteSQL, want) {
|
||||
t.Fatalf("run retention SQL missing %q in SQL:\n%s", want, runDeleteSQL)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user