Skip to content

test: replace time.Sleep with deterministic synchronization in health worker tests #83

@sangalo20

Description

@sangalo20

Problem

connection_health_test.go relies on time.Sleep to wait for the worker goroutine to execute, which can be flaky on slow or loaded CI runners.

Proposed Solution

Replace sleep-based synchronization with one of:

  1. RunOnce() method — expose a single-tick execution path that the test calls directly, removing the need for goroutines entirely.
  2. Channel-based sync — have mock methods (GetForHealthCheck, UpdateHealthStatus) signal on a channel so the test blocks until the expected call completes.

Option 1 is preferred as it simplifies tests and removes timing sensitivity altogether.

Files Affected

  • internal/service/connection_health.go — add RunOnce() or equivalent
  • internal/service/connection_health_test.go — rewrite to use deterministic sync

Priority

Low — the current 200ms sleep works reliably but is technically non-deterministic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions