Skip to content

test: remove flaky timing dependence from the test suite - #354

Merged
sgerbino merged 2 commits into
cppalliance:developfrom
sgerbino:pr/deflake-timing-tests
Sep 8, 2026
Merged

test: remove flaky timing dependence from the test suite#354
sgerbino merged 2 commits into
cppalliance:developfrom
sgerbino:pr/deflake-timing-tests

Conversation

@sgerbino

@sgerbino sgerbino commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Two classes of timing-based test could false-fail on a loaded runner, most visibly Windows Release under parallel CI.

Acceptor wait/accept suites (tcp_acceptor.cpp) gated success on a 250ms in-test watchdog that cancelled the operation and asserted it had not fired. On IOCP the wait is served by a background WSAPoll thread that posts a completion; under contention that cross-thread handoff can miss the deadline, tripping the watchdog on a correct build. The guarded operations are all genuinely satisfiable, so a working build completes on its own.

run_for / run_one_for suites (io_context.cpp, native_io_context.cpp) asserted elapsed wall-clock time fell within a fixed window. The upper bounds raced the scheduler between two now() samples; the lower bounds only restated that the timeout was honored. Both are removed, keeping the behavioral checks (n == 0, stopped()).

In every case a genuine hang now surfaces as a harness timeout, a correct fail signal, instead of a fixed in-test deadline that misfires under load.

No library change.

Two classes of timing-based test could false-fail on a loaded runner,
most visibly Windows Release under parallel CI.

Acceptor wait/accept suites (tcp_acceptor.cpp) gated success on a 250ms
in-test watchdog that cancelled the operation and asserted it had not
fired. On IOCP the wait is served by a background WSAPoll thread that
posts a completion; under contention that cross-thread handoff can miss
the deadline, tripping the watchdog on a correct build. The guarded
operations are all genuinely satisfiable, so a working build completes
on its own.

run_for / run_one_for suites (io_context.cpp, native_io_context.cpp)
asserted elapsed wall-clock time fell within a fixed window. The upper
bounds raced the scheduler between two now() samples; the lower bounds
only restated that the timeout was honored. Both are removed, keeping
the behavioral checks (n == 0, stopped()).

In every case a genuine hang now surfaces as a harness timeout, a
correct fail signal, instead of a fixed in-test deadline that misfires
under load.

No library change.
@cppalliance-bot

cppalliance-bot commented Sep 8, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://354.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-09-08 20:24:53 UTC

The forward completion callback runs on a system DNS thread and called
work_finished() before post(). work_finished() decrements the scheduler's
outstanding-work count and, at zero, wakes run() to return; post()
re-increments it. Between the two the count could reach zero, run() could
return, and the io_context -- with this resolver service -- could be
destroyed before post() ran, leaving svc_ a dangling reference: the
intermittent boost.corosio.resolver SEGFAULT seen only on Windows.

Post before work_finished so the posted op holds the count above zero
across the balance, and cache svc_ because the queued op may free the impl
the instant it is posted. Apply the same reorder to the reverse-resolve
pool completion and the synchronous GetAddrInfoExW path, which shared the
ordering.
@sgerbino
sgerbino merged commit 57faa32 into cppalliance:develop Sep 8, 2026
43 checks passed
@sgerbino
sgerbino deleted the pr/deflake-timing-tests branch September 8, 2026 22:03
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Beast2 Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants