Skip to content

Replace timing-based waits in tests with synchronisation - #5

Merged
umputun merged 1 commit into
masterfrom
fix/time-dependent-tests
Aug 19, 2026
Merged

umputun merged 1 commit into
masterfrom
fix/time-dependent-tests

Conversation

@paskal

@paskal paskal commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Previously, the shutdown tests slept for a fixed period and then asserted that the injected exit function had been called. That fails whenever the scheduler runs the timer later than the sleep, which is what happens on a loaded CI runner. The injected exit now reports through a channel, so each test waits only as long as it actually needs and fails on a deadline instead of on a guess.

Three cases needed more than a mechanical replacement:

  • The second-signal case ran with a 500ms shutdown timeout while asserting on an exit that the second signal was supposed to cause; the timeout could have produced that exit instead, so the test could pass for the wrong reason. Its timeout is now long enough that only the second signal can trigger the exit.
  • The concurrent-signals case keeps a short timeout deliberately. os/signal drops a send to a full channel, so a burst of signals may well be delivered once and the exit has to come from the timeout; the deterministic claim, that a second signal forces the exit, is what the case above covers. It now runs on a signal no other case sends and joins its senders, so nothing it sends can reach a later case.
  • The timeout accuracy case measured from before the signal that starts the timer and asserted a 150ms window around it. It now measures from the shutdown callback, runs on its own signal, and keeps the meaningful bound, that the forced exit never happens early; the upper bound stays loose enough to survive a delayed timer while still catching a timeout off by an order of magnitude.

The HTTP tests no longer sleep before the first request either: the listener is created before the server starts and already accepts connections, so the request blocks until Serve picks it up. Those requests now carry a client timeout, so a stuck server fails the test instead of hanging it. The sleeps in the example tests stay, as they pace the printed output and removing the one in Example_httpServerWithContext would race the server start against the cancellation.

Previously, the shutdown tests slept for a fixed period and then asserted that
the injected exit function had been called, which fails on a loaded machine
whenever the scheduler runs the timer later than the sleep. The injected exit
now reports through a channel, so each test waits exactly as long as it needs
to and fails on a deadline instead.

The second-signal case ran with a 500ms shutdown timeout while asserting on an
exit that the second signal was meant to cause, so the timeout could produce
that exit on its own; its timeout is now long enough that only the signal can.
The concurrent-signals case keeps a short timeout on purpose, as os/signal
drops a send to a full channel and a burst may therefore be delivered once, but
it now runs on a signal of its own and joins its senders, so nothing it sends
can reach a later case.

The timeout accuracy case measured from before the signal that starts the timer
and asserted a 150ms window around it. It now measures from the shutdown
callback, runs on its own signal, keeps the meaningful bound that the forced
exit never happens early, and leaves the upper one loose enough to survive a
delayed timer.

The HTTP tests no longer sleep before the first request, as the listener is
created before the server starts and already accepts connections; their
requests carry a client timeout, so a stuck server fails the test instead of
hanging it.
@paskal
paskal requested a review from umputun as a code owner August 19, 2026 01:23
@umputun
umputun merged commit e77136d into master Aug 19, 2026
4 checks passed
@umputun
umputun deleted the fix/time-dependent-tests branch August 19, 2026 01:53
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