From 6a45846ae75bdf5c4372950363364475655267d3 Mon Sep 17 00:00:00 2001 From: Lukasz Dziedziak Date: Fri, 31 Jan 2025 09:31:43 -0500 Subject: [PATCH] fix Signed-off-by: Lukasz Dziedziak --- pkg/util/watchdog/watchdog.go | 6 +++--- pkg/util/watchdog/watchdog_test.go | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/util/watchdog/watchdog.go b/pkg/util/watchdog/watchdog.go index 1086af163047..e013d5f7d04a 100644 --- a/pkg/util/watchdog/watchdog.go +++ b/pkg/util/watchdog/watchdog.go @@ -48,13 +48,13 @@ func (w *SimpleWatchdog) Start(ctx context.Context) { w.OnError(err) } } + if w.hasTickedChan != nil && !channels.IsClosed(w.hasTickedChan) { // On the first tick we close the channel + close(w.hasTickedChan) + } select { case <-ctx.Done(): case <-ticker.C: } - if w.hasTickedChan != nil && !channels.IsClosed(w.hasTickedChan) { // On the first tick we close the channel - close(w.hasTickedChan) - } // cases are non prioritized so we first check is the context is done select { case <-ctx.Done(): diff --git a/pkg/util/watchdog/watchdog_test.go b/pkg/util/watchdog/watchdog_test.go index 088ee7695e52..db34cd113ef6 100644 --- a/pkg/util/watchdog/watchdog_test.go +++ b/pkg/util/watchdog/watchdog_test.go @@ -215,15 +215,16 @@ var _ = Describe("SimpleWatchdog", func() { watchdog.Start(ctx) close(doneCh) }() - Expect(watchdog.HasTicked(false)).Should(BeFalse()) - Consistently(hasTicked, "100ms", "10ms").ShouldNot(Receive()) + // first onTick call + Eventually(func(g Gomega) { + g.Expect(watchdog.HasTicked(false)).Should(BeTrue()) + }, "100ms", "10ms").Should(Succeed()) + Expect(hasTicked).Should(BeClosed()) By("simulating 1st tick") // when timeTicks <- time.Time{} - Eventually(func(g Gomega) { - g.Expect(watchdog.HasTicked(false)).Should(BeTrue()) - }, "100ms", "10ms").Should(Succeed()) + Expect(watchdog.HasTicked(false)).Should(BeTrue()) Expect(hasTicked).Should(BeClosed()) By("simulating 2nd tick")