Skip to content

tests: wait on events instead of sleeps in the cli crate tests - #14821

Merged
TrapsterDK merged 4 commits into
mainfrom
tests/event-waits-process
Nov 24, 2026
Merged

TrapsterDK merged 4 commits into
mainfrom
tests/event-waits-process

Conversation

@TrapsterDK

Copy link
Copy Markdown
Collaborator

Stacked on #14818 (uses its dx_test_scratch::wait helpers).

Replaces fixed sleeps and sleep-poll loops in cli test code with event waits that have a deadline: pid exit (pidfd/kqueue/process handle), lock coming free (blocking File::lock in a thread), path appearing (notify), a fifo or held pipe for children that must stay alive, and peer socket close for stalled HTTP servers. eventually is removed from dx_test_scratch.

Flake fixed: exec_launcher_test run_scrubs_unset_variables retried on ETXTBSY because fs::copy held a write fd that a concurrently forked test thread inherited; the copy now runs in cp.

Review paths: cli/process/, cli/atomic_fs/, cli/worktree/.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus

TrapsterDK and others added 2 commits November 24, 2026 09:15
dx_test_scratch::wait adds bounded waits on real conditions: a path
appearing (notify), a lock coming free, a pid exiting (pidfd, kqueue,
WaitForSingleObject via dx_os_sys::exit) and a child exiting under a
deadline. dx_testing, the process and nested probes, the nested
harness and reaper, the lsp session and the maven pin use them in place
of sleep-and-poll loops. Long-lived stand-in children block on stdin
instead of sleeping. dx_testing::rlocation opens the runfiles manifest
once instead of on every call, which made module_extension_srcs_test
time out on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
Process, lease, prune, lock, http, shim, launcher, os_sys and worktree
tests now wait on the real event with a deadline: a pid exiting, a lock
coming free, a path appearing, a fifo or pipe that never gets a writer,
or a peer closing its socket. Long-running sleep children become cat or
read on a held pipe. The launcher copy goes through cp so no forked
thread inherits a write fd, which removes the ETXTBSY retry loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
@TrapsterDK TrapsterDK added the needs-review Touches review paths; needs a second-session Review: comment label Nov 24, 2026
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["linux_x86_64","macos_arm64","windows_x86_64"] task=test scope=//cli/process:all //cli/atomic_fs:all //cli/setup:all //cli/lock:all //cli/http:all //cli/shim:all //cli/launcher:all //cli/os_sys:all //cli/worktree:all //cli/test_scratch:all

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review:

  • cli/setup/src/prune/apply.rs:341 - panic!("{what}: {error}"); sits on its own line in a branch that only runs on failure. This file is library source, so the line counts toward the 100% coverage gate (ci.yml:147) and is never hit. The old loop body did run. - Put it on one line, as lease.rs does: .unwrap_or_else(|error| panic!("{what}: {error}"));
  • cli/os_sys/src/signals_tests.rs:58 - loop { std::thread::park(); } sits in a function that returns (). .bazelrc:55 denies clippy::infinite_loop, and TEST_EXEMPT_LINTS does not exempt it. clippy-driver 1.99 with -Dclippy::infinite_loop flags this exact code. The fixture_resolver.rs:103 loop in main has the same shape and was already there before this PR, so check what lint reports for this target. - Move the loop into fn park_forever() -> ! { loop { std::thread::park() } } and call that.
  • cli/os_sys/src/signals_tests.rs:58, cli/process/src/lifecycle_tests.rs:1389, cli/process/src/lifecycle_tests.rs:2042 - These children used to end on their own: after 30 s, after sleep 3, after exec sleep 30. Now they park, or block on a fifo, forever. If the code under test regresses (no 143 exit, a stop or kill not sent), the test hangs until the Bazel timeout instead of failing an assert. The parent .status() at signals_tests.rs:71 has no deadline. - Bound the parent wait with dx_test_scratch::wait::exit_within(child, limit) and assert on Exit::Exited. For the two lifecycle tests, accept the hang or run the call inside wait::within.
  • cli/process/src/lifecycle_tests.rs:1124 - The sigints deadline went from 5 s to 10 s. The rule here is no longer timeouts. - Keep Duration::from_secs(5).

Checked and fine: lease and alive-lock waits (std flock/LockFileEx on both sides; hold_alive_lock locks before it renames, so wait_armed followed by one alive_lock_held check has no race), head -c 2 on the up fifo (the probe writes up after it takes the lock and never writes again), cmd /K "echo ready& ..." quoting, the Counting condvar (overlap 0 never waits), the SENT table replacing the b_log == 0 check, and cp replacing the ETXTBSY retry.

Park in a function that never returns, bound the signals child with
exit_within so a broken stop path fails instead of hanging, keep the
SIGINT wait at 5 s, and keep failure-only messages on covered lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review findings addressed in 91576ca: (1) apply.rs wait_for panics on one covered line; (2) park moved into fn park_forever() -> ! in signals_tests.rs and fixture_resolver.rs; (3) the signals parent now waits with exit_within(child, 30s) and fails on a hang. The two lifecycle shells stay blocked on a fifo: the runner under test owns their deadline (200 ms timeout, stop probe), and the Bazel test timeout bounds a broken kill path; (4) the SIGINT wait is back to 5 s.

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

/evidence platforms=["linux_x86_64","macos_arm64","windows_x86_64"] task=test scope=//cli/process:all //cli/atomic_fs:all //cli/setup:all //cli/lock:all //cli/http:all //cli/shim:all //cli/launcher:all //cli/os_sys:all //cli/worktree:all //cli/test_scratch:all

Base automatically changed from tests/event-waits to main November 24, 2026 09:38
Keep the locked, locked_shared and unlocking lock_free helpers, and lower
the sleep budget to what is left after the event-wait PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus
@TrapsterDK
TrapsterDK merged commit 2d1e63d into main Nov 24, 2026
17 of 27 checks passed
@TrapsterDK
TrapsterDK deleted the tests/event-waits-process branch November 24, 2026 09:40
TrapsterDK added a commit that referenced this pull request Nov 24, 2026
…ts (#14832)

#14821 added @crates//:notify to both BUILD files without declaring it in
their Cargo.toml, so generate stops with unresolved import "notify" once
the cfg(test) parse errors are gone. Declare it, repin dx_crates and take
the buildifier wrapping generate now applies to fortran and haskell tests.


Claude-Session: https://claude.ai/code/session_01Xut2hyBydsMejdwk6QdKus

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Touches review paths; needs a second-session Review: comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant