Skip to content

Commit

Permalink
Add SpeedUpForUT function to sched package (#2484)
Browse files Browse the repository at this point in the history
* Add SpeedUpForUT function to sched package

---------

Signed-off-by: Tengxiao Wang <[email protected]>
  • Loading branch information
twang-ps authored Sep 20, 2024
1 parent 464a4a2 commit 2478442
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit 2478442

Please sign in to comment.