Skip to content

resource: fix parallel-run flake in the memory ledger test - #204

Merged
congwang-mk merged 1 commit into
mainfrom
resource-test-parallel-race
Aug 23, 2026
Merged

resource: fix parallel-run flake in the memory ledger test#204
congwang-mk merged 1 commit into
mainfrom
resource-test-parallel-race

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

reconcile_raises_a_laundered_ledger_to_the_measured_footprint asserts exact figures against the test process's own statm while sibling tests move it. Its sibling measured_footprint_tracks_anonymous_not_file_mappings maps a gigabyte of anonymous memory, which is exactly the headroom the ledger test budgeted for sibling noise, so under a parallel run (the default cargo test; CI's --test-threads=1 hides it) the mapping can land between the ledger test's two reconciles. The measure then tops the inflated ledger and the floor legitimately raises it, failing the assert by the sibling's gigabyte plus a few pages of noise.

Fix: fork a child parked in pause() and point reconcile_floor at that pid instead of the shared process. The child's address space is frozen at fork, so its measure cannot move, the headroom assumption disappears, and the restored ledger is again checked against a separately taken reading (an exact-equality assertion the racy self-measure version had to give up). A Drop impl SIGKILLs and reaps the child so nothing leaks on assert failure. The mapping test keeps measuring itself, since it must own the address space it maps into; its existing wide margins were always sufficient once the ledger test stopped depending on them.

The flake was observed on a full parallel suite run (overshoot of exactly 1 GiB + 3 pages, matching the sibling's mapping); it is timing-dependent and not reproducible on demand, but the fix removes the interleaving by construction. The three memory_range_tests pass locally.

reconcile_raises_a_laundered_ledger_to_the_measured_footprint asserted
exact figures against this process's own statm while sibling tests move
it: measured_footprint_tracks_anonymous_not_file_mappings maps a
gigabyte of anonymous memory, exactly the headroom the ledger test
budgeted for sibling noise, so a parallel run could land the mapping
between the two reconciles and the floor legitimately raised the
inflated ledger. Fork a child parked in pause() and measure that
instead: its footprint is frozen at fork, so the headroom assumption
goes away and the restored ledger can be checked against a separately
taken reading.

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk
congwang-mk merged commit 33f13c9 into main Aug 23, 2026
17 checks passed
@congwang-mk
congwang-mk deleted the resource-test-parallel-race branch August 23, 2026 16:29
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