pub fn wait_for_worker_ready(
worker: &mut PayloadHandle,
worker_pid: u32,
timeout: Duration,
role: &str,
exit_code_legend: &str,
) -> Result<()>Expand description
Poll for the worker’s ready marker with a deadline, returning early if the worker exits before writing the marker or after writing but before the caller’s subsequent dispatch.
Event-driven via inotify on the marker’s parent directory
(IN_CREATE | IN_MOVED_TO). The wait wakes on the actual file-
create edge — kernel-scheduling-tick latency — instead of a
10 ms poll tail. inotify is set up BEFORE the initial existence
probe so a marker that lands between probe and watch-add still
fires the watch on a subsequent edge; the loop body re-checks
existence on every wake so a stale watch edge from an unrelated
file in the same directory doesn’t false-fire.
The caller supplies role (e.g. "worker", "churn worker") and
exit_code_legend (a variant-specific decoder for the
worker-binary exit codes the caller wants printed in the error
message). Worker cleanup on timeout happens via
PayloadHandle::drop when the caller’s Result error
propagates — calling PayloadHandle::kill(self) here would take
the handle by value, which we can’t do behind an &mut borrow.
Consolidates what used to be two near-identical 20-line poll
loops in tests/jemalloc_probe_tests.rs — a rename of the marker
path, a change in poll interval, or a new early-exit shape now
edits one site instead of two.