mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
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:
@ -103,6 +103,8 @@ func (w *Watchdog) publishLoop() {
|
|||||||
|
|
||||||
func (w *Watchdog) subscribeMonitor() {
|
func (w *Watchdog) subscribeMonitor() {
|
||||||
defer w.wg.Done()
|
defer w.wg.Done()
|
||||||
|
tmr := w.clock.Timer(periodTimeout)
|
||||||
|
defer tmr.Stop()
|
||||||
beats := make(chan struct{})
|
beats := make(chan struct{})
|
||||||
unsub, err := w.ps.Subscribe(EventPubsubWatchdog, func(context.Context, []byte) {
|
unsub, err := w.ps.Subscribe(EventPubsubWatchdog, func(context.Context, []byte) {
|
||||||
w.logger.Debug(w.ctx, "got heartbeat for pubsub watchdog")
|
w.logger.Debug(w.ctx, "got heartbeat for pubsub watchdog")
|
||||||
@ -117,8 +119,6 @@ func (w *Watchdog) subscribeMonitor() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer unsub()
|
defer unsub()
|
||||||
tmr := w.clock.Timer(periodTimeout)
|
|
||||||
defer tmr.Stop()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-w.ctx.Done():
|
case <-w.ctx.Done():
|
||||||
|
Reference in New Issue
Block a user