Skip to content

Commit

Permalink
fix(watchdog): wait for the first tick (#12693)
Browse files Browse the repository at this point in the history
## Motivation

Issue: #12657


## Implementation information

Changed to wait for the `HasTicked` to be called before first Ticker
event, since there was a race and sometimes on ticked happened before
the assertion

fix: #12657

---------

Signed-off-by: Lukasz Dziedziak <lukidzi@gmail.com>
  • Loading branch information
lukidzi authored Feb 5, 2025
1 parent 1c4235b commit 73b4d0e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/util/watchdog/watchdog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ var _ = Describe("SimpleWatchdog", func() {
}))

It("should wait for the first tick to happen on WaitForFirstTick", func() {
onTickBlockCh := make(chan struct{})
watchdog := &SimpleWatchdog{
NewTicker: func() *time.Ticker {
return &time.Ticker{
C: timeTicks,
}
},
OnTick: func(ctx context.Context) error {
<-onTickBlockCh
return nil
},
OnError: func(err error) {
Expand All @@ -215,8 +217,15 @@ var _ = Describe("SimpleWatchdog", func() {
watchdog.Start(ctx)
close(doneCh)
}()
// before the first OnTick returns false
Expect(watchdog.HasTicked(false)).Should(BeFalse())
Consistently(hasTicked).ShouldNot(Receive())
// unblock OnTick
close(onTickBlockCh)
// after the first tick returns true
Eventually(func(g Gomega) {
g.Expect(watchdog.HasTicked(false)).To(BeTrue())
}, "100ms", "10ms").Should(Succeed())
Expect(hasTicked).Should(BeClosed())

By("simulating 1st tick")
// when
Expand Down

0 comments on commit 73b4d0e

Please sign in to comment.