fix: start timer before subscribing to avoid test race (#12031)

Fixes #12030

This is a good example of the kind of thing I'd like to address with a time-testing lib.  The problem is that there is a race between the watchdog starting it's timer and the test incrementing the time.  What would make this easier is if the time-testing library could wait for and assert the call to start the timer before incrementing the time.
This commit is contained in:
Spike Curtis 2024-02-06 20:21:23 +04:00 committed by GitHub
parent b6806bca70
commit 213ae69bee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -103,6 +103,8 @@ func (w *Watchdog) publishLoop() {
func (w *Watchdog) subscribeMonitor() {
defer w.wg.Done()
tmr := w.clock.Timer(periodTimeout)
defer tmr.Stop()
beats := make(chan struct{})
unsub, err := w.ps.Subscribe(EventPubsubWatchdog, func(context.Context, []byte) {
w.logger.Debug(w.ctx, "got heartbeat for pubsub watchdog")
@ -117,8 +119,6 @@ func (w *Watchdog) subscribeMonitor() {
return
}
defer unsub()
tmr := w.clock.Timer(periodTimeout)
defer tmr.Stop()
for {
select {
case <-w.ctx.Done():