Skip to content

Commit

Permalink
fix(kuma-cp): don't wait before ticking the first time in watchdog (#…
Browse files Browse the repository at this point in the history
…11105)

This delays xds config generation unnecessarily. Closes #11094

* fix(kuma-cp): don't wait before ticking the first time in watchdog
* test(watchdog): update test flow because we immedately trigger once

Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont authored Aug 13, 2024
1 parent 4551830 commit 2208412
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
19 changes: 11 additions & 8 deletions pkg/util/watchdog/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ func (w *SimpleWatchdog) Start(stop <-chan struct{}) {
case <-ctx.Done():
}
}()

select {
case <-ticker.C:
select {
case <-stop:
default:
if err := w.onTick(ctx); err != nil && !errors.Is(err, context.Canceled) {
w.OnError(err)
}
case <-stop:
default:
if err := w.onTick(ctx); err != nil && !errors.Is(err, context.Canceled) {
w.OnError(err)
}
}
cancel()

select {
case <-ticker.C:
continue
case <-stop:
if w.OnStop != nil {
w.OnStop()
}
// cancel will be called by the above goroutine
return
}
cancel()
}
}

Expand Down
13 changes: 2 additions & 11 deletions pkg/util/watchdog/watchdog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ var _ = Describe("SimpleWatchdog", func() {
close(doneCh)
}()

By("simulating 1st tick")
// when
timeTicks <- time.Time{}

// then
// then first tick happens "immediately"
<-onTickCalls

By("simulating 2nd tick")
Expand Down Expand Up @@ -98,11 +94,7 @@ var _ = Describe("SimpleWatchdog", func() {
close(doneCh)
}()

By("simulating 1st tick")
// when
timeTicks <- time.Time{}

// then
// then first tick happens "immediately"
actualErr := <-onErrorCalls
Expect(actualErr).To(MatchError(expectedErr))

Expand Down Expand Up @@ -135,7 +127,6 @@ var _ = Describe("SimpleWatchdog", func() {
watchdog.Start(stopCh)
close(doneCh)
}()
timeTicks <- time.Time{}

// then watchdog returned an error
Expect(<-onErrorCalls).To(HaveOccurred())
Expand Down

0 comments on commit 2208412

Please sign in to comment.