Skip to content

Commit 73b4d0e

Browse files
authored
fix(watchdog): wait for the first tick (#12693)
## 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 <[email protected]>
1 parent 1c4235b commit 73b4d0e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/util/watchdog/watchdog_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,15 @@ var _ = Describe("SimpleWatchdog", func() {
190190
}))
191191

192192
It("should wait for the first tick to happen on WaitForFirstTick", func() {
193+
onTickBlockCh := make(chan struct{})
193194
watchdog := &SimpleWatchdog{
194195
NewTicker: func() *time.Ticker {
195196
return &time.Ticker{
196197
C: timeTicks,
197198
}
198199
},
199200
OnTick: func(ctx context.Context) error {
201+
<-onTickBlockCh
200202
return nil
201203
},
202204
OnError: func(err error) {
@@ -215,8 +217,15 @@ var _ = Describe("SimpleWatchdog", func() {
215217
watchdog.Start(ctx)
216218
close(doneCh)
217219
}()
220+
// before the first OnTick returns false
218221
Expect(watchdog.HasTicked(false)).Should(BeFalse())
219-
Consistently(hasTicked).ShouldNot(Receive())
222+
// unblock OnTick
223+
close(onTickBlockCh)
224+
// after the first tick returns true
225+
Eventually(func(g Gomega) {
226+
g.Expect(watchdog.HasTicked(false)).To(BeTrue())
227+
}, "100ms", "10ms").Should(Succeed())
228+
Expect(hasTicked).Should(BeClosed())
220229

221230
By("simulating 1st tick")
222231
// when

0 commit comments

Comments
 (0)