Skip to content

test: verify waker contract boundaries in Latch and Barrier - #499

Open
nanami-0713 wants to merge 1 commit into
apache:mainfrom
nanami-0713:deslopify/latch-barrier-waker-tests
Open

nanami-0713 wants to merge 1 commit into
apache:mainfrom
nanami-0713:deslopify/latch-barrier-waker-tests

Conversation

@nanami-0713

Copy link
Copy Markdown
Contributor

Summary

  • Latch and Barrier wake waiters and destroy replaced or cancelled wakers outside their waiter locks, but no test guarded those boundaries: with all six wake and drop sites moved back under the lock, the pre-existing Latch and Barrier tests still passed.
  • Add integration tests that re-enter Latch and Barrier from wake and waker-drop callbacks and that re-poll with a new waker to check the replaced waker is released. The existing Barrier generation tests now also assert that followers are woken before they are polled.
  • Add one #[cfg(test)] probe for the Latch zero transition. Terminal Latch waits are lock-free, so a public-API re-entry cannot tell whether wake_all runs under the waiter lock; the probe uses try_lock inside the wake callback, like the Completion probe in test(completion): verify wake callbacks run outside waiter lock #482.

Production code is unchanged.

Validation

Local validation on macOS (aarch64-apple-darwin, stable rustc 1.99.1, nightly 1.102.0-nightly from 2026-11-08):

  • cargo x check
  • cargo x test — 788 tests passed, including 177 doc tests
  • cargo x lint — clippy, taplo, typos, hawkeye, and the docsrs rustdoc check pass. The rustfmt step stops on two doc-comment diffs in asyncband/src/mpsc/bounded/receiver.rs, which is unchanged here and shows the same diffs on main (b6b8adf) with this nightly; the files touched by this PR are rustfmt-clean.
  • cargo x miri — 574 tests passed; 14 existing tests are ignored under Miri

Mutation checks in a temporary source copy, each moving one site back under the lock:

Mutation Failing test
Latch::arrive wakes under the waiter lock latch::tests::arrive_wakes_outside_waiter_lock
Latch drops the replaced waker under the waiter lock latch_test::waker_callbacks_can_reenter_the_latch
Latch drops the cancelled waker under the waiter lock latch_test::waker_callbacks_can_reenter_the_latch
Barrier drops the replaced waker under the barrier lock barrier_test::wake_and_waker_destruction_happen_outside_the_barrier_lock
Barrier leader wakes followers under the barrier lock barrier_test::wake_and_waker_destruction_happen_outside_the_barrier_lock
Barrier drops the cancelled waker under the barrier lock barrier_test::wake_and_waker_destruction_happen_outside_the_barrier_lock

Each mutation failed exactly one test and nothing else. With all six mutations applied together and the pre-PR latch_test and barrier_test restored in place of the new ones, the remaining Barrier unit test and the 21 integration tests in latch_test, barrier_test, and shutdown_test still passed.

This branch has not been deployed

No deployments
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.

1 participant