Files
geo/server/internal/scheduler/scheduler_run_retention_worker_test.go
T
root 49b1ccc961
Backend CI / Backend (push) Successful in 14m44s
Reduce scheduler polling noise
2026-05-21 00:56:43 +08:00

54 lines
1.7 KiB
Go

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