perf(scheduler): harden jobs for scalable execution
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSchedulerLoopSleepCapsManualPollWithoutForcingAutoRun(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 10, 0, 0, 0, time.UTC)
|
||||
nextAutoAt := now.Add(time.Minute)
|
||||
|
||||
got := schedulerLoopSleep(now, nextAutoAt)
|
||||
if got != schedulerManualPollInterval {
|
||||
t.Fatalf("schedulerLoopSleep() = %s, want %s", got, schedulerManualPollInterval)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextIntervalAutoAtUsesLastRunOnInitialStart(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 10, 0, 0, 0, time.UTC)
|
||||
last := now.Add(-time.Minute)
|
||||
|
||||
got := nextIntervalAutoAt(now, 5*time.Minute, true, &last)
|
||||
want := last.Add(5 * time.Minute)
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("nextIntervalAutoAt() = %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextIntervalAutoAtRunsImmediatelyWhenOverdue(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 10, 0, 0, 0, time.UTC)
|
||||
last := now.Add(-10 * time.Minute)
|
||||
|
||||
got := nextIntervalAutoAt(now, 5*time.Minute, true, &last)
|
||||
if !got.Equal(now) {
|
||||
t.Fatalf("nextIntervalAutoAt() = %s, want %s", got, now)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextIntervalAutoAtSchedulesAfterCurrentCompletion(t *testing.T) {
|
||||
now := time.Date(2026, 5, 20, 10, 0, 0, 0, time.UTC)
|
||||
|
||||
got := nextIntervalAutoAt(now, 5*time.Minute, false, nil)
|
||||
want := now.Add(5 * time.Minute)
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("nextIntervalAutoAt() = %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user