test(service): deterministic sync for health worker tests (#83)#85
Merged
sangalo20 merged 2 commits intoJun 17, 2026
Merged
Conversation
…ing (Prescott-Data#83) Remove brittle time.Sleep-based waiting from connection health worker tests. Use channel-based synchronization tied to expected repository update calls so assertions run exactly when the worker completes a check iteration.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR makes the ConnectionHealthWorker tests deterministic by removing fixed sleeps and instead waiting for a mock callback signal when the worker updates connection health.
Changes:
- Added a
runWorkerUntilSignalhelper to start the worker and wait for a completion signal with a timeout. - Updated multiple tests to close a
donechannel fromUpdateHealthStatusmock.Run(...)and wait on it instead oftime.Sleep.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+30
| case <-time.After(2 * time.Second): | ||
| t.Fatal("timed out waiting for health worker signal") |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+30
to
+40
| select { | ||
| case <-done: | ||
| case <-time.After(2 * time.Second): | ||
| cancel() | ||
| select { | ||
| case <-workerDone: | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("timed out waiting for health worker to stop after signal timeout") | ||
| } | ||
| t.Fatal("timed out waiting for health worker signal") | ||
| } |
Comment on lines
+160
to
+163
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "healthy"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+202
to
+205
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "expired"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+245
to
+248
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "unhealthy"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+298
to
+301
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "expired"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+334
to
+337
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "unhealthy"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+369
to
+372
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "degraded"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
Comment on lines
+404
to
+407
| done := make(chan struct{}) | ||
| mockRepo.On("UpdateHealthStatus", mock.Anything, connID, "degraded"). | ||
| Run(func(args mock.Arguments) { close(done) }). | ||
| Return(nil).Once() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unWorkerUntilSignal helper to drive worker execution until a known repository update call occurs.
Why
Issue #83 calls out test instability from fixed sleeps. This refactor makes tests deterministic and faster by synchronizing on actual worker side effects.
Test plan