Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpeedUpForUT function to sched package #2484

Merged
merged 11 commits into from
Sep 20, 2024
8 changes: 8 additions & 0 deletions pkg/sched/intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
var (
// speedUp advances the clock faster for tests.
speedUp = false
// speedUpIntervalForUT overrides the interval of schedules in unit tests; no-op if set to 0
speedUpIntervalForUT = time.Duration(0)
)

// SpeedUp advances the clock faster for tests.
Expand All @@ -38,6 +40,10 @@ func inSpeedUp() bool {
return speedUp
}

func SpeedUpForUT(duration time.Duration) {
speedUpIntervalForUT = duration
}

type IntervalSpec struct {
Freq string
Period uint64 `yaml:"period,omitempty"`
Expand Down Expand Up @@ -560,6 +566,8 @@ func (p RetainIntervalImpl) nextAfter(t time.Time) time.Time {
newTime := p.iv.nextAfter(t)
if inSpeedUp() {
return t.Add(time.Minute)
} else if speedUpIntervalForUT != time.Duration(0) {
return t.Add(speedUpIntervalForUT)
}
return newTime
}
Expand Down
Loading