Skip to content

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

Open
ashioyajotham wants to merge 1 commit into
Prescott-Data:mainfrom
ashioyajotham:test/health-worker-deterministic-sync-83
Open

test(service): deterministic sync for health worker tests (#83)#85
ashioyajotham wants to merge 1 commit 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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 on lines +23 to +31
defer cancel()

go worker.Start(ctx)

select {
case <-done:
case <-time.After(2 * time.Second):
t.Fatal("timed out waiting for health worker signal")
}
Comment on lines +29 to +30
case <-time.After(2 * time.Second):
t.Fatal("timed out waiting for health worker signal")
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.

2 participants