Skip to content

flaky: the_intrusive_free_list_round_trips_a_whole_cohort asserts a delta on a process-global counter under parallel tests #8401

Description

@proggeramlug

Flaky: the_intrusive_free_list_round_trips_a_whole_cohort asserts a delta on a process-global counter

crates/perry-runtime/src/box/release_tests.rs:485 fails intermittently:

box::release_tests::the_intrusive_free_list_round_trips_a_whole_cohort
assertion `left == right` failed: second cohort allocates N cells
  left: 515
 right: 512

Observed 3 times tonight across unrelated branches while validating #8392, #8397 and
#8399, always as a single failure in an otherwise green cargo test --release -p perry-runtime --lib (2594 passed / 1 failed), and never reproducible in isolation — the
same suite reruns clean, and the test passes on its own every time.

Cause

The assertions bracket a global counter:

let (a0, r0, _) = box_release_stats();
let second: Vec<*mut Box> = (0..N).map(...).collect();
let (a1, r1, _) = box_release_stats();
assert_eq!(a1 - a0, N as u64, "second cohort allocates N cells");

box_release_stats() is process-wide, but cargo test runs the suite multi-threaded. Any
other test that allocates a box between the two reads inflates the delta. 515 - 512 = 3
stray allocations from a concurrent test, not a free-list defect.

The intent of the test is sound and worth keeping — it pins that all N cells come from the
intrusive free list rather than falling through to std::alloc. Only the measurement is
unsound under parallelism.

Suggested fix

Either serialize it against other box-allocating tests (a shared mutex / serial_test-style
guard), or make the accounting local — e.g. snapshot and compare free-list occupancy for the
cells this test minted rather than a global allocation counter.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions