Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
lukidzi committed Jan 31, 2025
1 parent 0bab99e commit 6a45846
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/util/watchdog/watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
11 changes: 6 additions & 5 deletions pkg/util/watchdog/watchdog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6a45846

Please sign in to comment.