test: serialize cap_gate counter tests against each other (#131) - #147
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
filament | 1f5612d | Commit Preview URL Branch Preview URL |
Aug 06 2026, 08:47 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make
capability::tests::shadow_detector_proof_six_buckets(and every other test that touches the process-global counters) immune to concurrent interleaving, by serializing them on a shared test-only mutex. Production code untouched.Why it is not hygiene
The test snapshots six process-global atomic counters, calls
cap_gate_effective, and asserts on DELTAS.cargo testruns tests in parallel; any concurrent test touching the same counters between the snapshot and the call breaks the delta. This test went RED on PR #143, a CHANGELOG-ONLY diff, against a main that was green minutes earlier. A flaky test invites a retry; a test that failed on a docs-only PR is a real race.The race, reproduced without the lock
Baseline (this branch with the lock removed), 60 runs of
capability::tests --test-threads=4:With the lock, same 60 runs:
The fix
A single
CAP_GATE_TEST_LOCKdeclared inside#[cfg(test)] mod tests. All 11 test functions that callcap_gate_effectiveacquire it (2 revoke, per-action bucket, six-bucket proof, 7 fleet gates). The six-bucket proof holds it across every snapshot/call pair. A panic while holding poisons the mutex, so subsequent tests fail loudly rather than silently interleaving.Verification
cargo test --profile measure capability::tests: 20 passed (all module tests, includes the 11)git diff --checkcleancap_gate_effectiveunchanged; the lock and its guard arecfg(test)onlyNote: this PR cannot merge while GitHub Actions is down (no checks can run); pushing and holding as directed.