test: subscribe to heartbeats synchronously on PGCoord startup (#21746)

fixes: https://github.com/coder/internal/issues/1304

Subscribe to heartbeats synchronously on startup of PGCoordinator. This ensures tests that send heartbeats don't race with this subscription.
This commit is contained in:
Spike Curtis
2026-01-29 13:34:34 +04:00
committed by GitHub
parent 62704eb858
commit 06e396188f
+6 -4
View File
@@ -1509,7 +1509,7 @@ func newHeartbeats(
clock: clk,
}
h.wg.Add(3)
go h.subscribe()
h.subscribe()
go h.sendBeats()
go h.cleanupLoop()
return h
@@ -1560,9 +1560,11 @@ func (h *heartbeats) subscribe() {
}
return
}
// cancel subscription when context finishes
defer cancel()
<-h.ctx.Done()
go func() {
// cancel subscription when context finishes
<-h.ctx.Done()
cancel()
}()
}
func (h *heartbeats) listen(_ context.Context, msg []byte, err error) {