Fix issue with tests failing due to test-related race conditions.

This commit is contained in:
2025-11-25 17:10:44 +00:00
parent 32e88efd9a
commit 035b1cdd01
2 changed files with 18 additions and 4 deletions
+16 -3
View File
@@ -154,12 +154,21 @@ func (s *WatchdogTestSuite) TestMultipleWorkers() {
s.watchdog.RegisterWorker("worker-3", makeCallback("worker-3"))
// worker-1: Keep sending heartbeats (healthy)
// Use a done channel to ensure goroutine exits before test ends
ticker1 := time.NewTicker(50 * time.Millisecond)
defer ticker1.Stop()
done := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
defer ticker1.Stop()
for i := 0; i < 10; i++ {
<-ticker1.C
s.watchdog.Heartbeat("worker-1")
select {
case <-ticker1.C:
s.watchdog.Heartbeat("worker-1")
case <-done:
return
}
}
}()
@@ -172,6 +181,10 @@ func (s *WatchdogTestSuite) TestMultipleWorkers() {
// Wait for hung workers to be detected
time.Sleep(600 * time.Millisecond)
// Signal goroutine to stop and wait for it
close(done)
wg.Wait()
// Check results
mu.Lock()
defer mu.Unlock()