Skip to content

test(service): deterministic sync for health worker tests (#83)#85

Merged
sangalo20 merged 2 commits into
Prescott-Data:mainfrom
ashioyajotham:test/health-worker-deterministic-sync-83
Jun 17, 2026
Merged

test(service): deterministic sync for health worker tests (#83)#85
sangalo20 merged 2 commits into
Prescott-Data:mainfrom
ashioyajotham:test/health-worker-deterministic-sync-83

Conversation

@ashioyajotham

Copy link
Copy Markdown
Contributor

Summary

  • Replace ime.Sleep waits in connection_health_test.go with deterministic channel-based synchronization.
  • Add
    unWorkerUntilSignal helper to drive worker execution until a known repository update call occurs.
  • Keep behavioral assertions unchanged while reducing timing flakiness.

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

  • go test ./internal/service/... -count=1
  • go test ./... -count=1 -timeout 180s (nexus-broker)

…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.
Copilot AI review requested due to automatic review settings May 27, 2026 15:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 runWorkerUntilSignal helper to start the worker and wait for a completion signal with a timeout.
  • Updated multiple tests to close a done channel from UpdateHealthStatus mock .Run(...) and wait on it instead of time.Sleep.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread nexus-broker/internal/service/connection_health_test.go Outdated
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>
Copilot AI review requested due to automatic review settings June 17, 2026 06:04
@sangalo20 sangalo20 merged commit 0103dcc into Prescott-Data:main Jun 17, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 8 comments.

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants