Skip to content

Commit

Permalink
Rename variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed May 8, 2020
1 parent 956a263 commit c9f3b8d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ var nowValue = struct{}{}
// RunOnceThrottled makes sure execution happens at most once per interval.
func (c *Controller) RunOnceThrottled(ctx context.Context) error {
now := time.Now()
testing := false
testEnv := false
if v, ok := ctx.Value(nowValue).(time.Time); ok {
now = v
testing = true
testEnv = true
}
if c.running || now.Before(c.minStartTime) {
// When throttled in non-test environment this function is no-op
// In test environment function returns an error so we can test it
if testing {
if testEnv {
return errors.New("throttled")
}
return nil
Expand All @@ -141,7 +141,7 @@ func (c *Controller) RunOnceThrottled(ctx context.Context) error {
defer func() {
c.running = false
}()
if testing {
if testEnv {
return nil
}
return c.RunOnce(ctx)
Expand Down

0 comments on commit c9f3b8d

Please sign in to comment.