Skip to content

Commit 62c6846

Browse files
author
Ralph Küpper
committed
test(runtime): isolate intrusive free-list assertions
1 parent 55a5b5a commit 62c6846

1 file changed

Lines changed: 7 additions & 37 deletions

File tree

crates/perry-runtime/src/box/release_tests.rs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@ fn install_test_activation(activation: *mut AsyncBoxActivation) -> crate::promis
1313
})
1414
}
1515

16-
/// `BOX_ALLOC_COUNT` / `BOX_POOL_REUSE_COUNT` / `BOX_RELEASE_COUNT` are
17-
/// process-global atomics, while the registries, quarantines and free
18-
/// lists they describe are THREAD-LOCAL. Any test that asserts on a
19-
/// counter *delta* is therefore not isolated by `test_clear_box_registry`
20-
/// alone — a sibling test allocating on another harness thread lands in
21-
/// the same atomics and moves the delta under it. Observed exactly that:
22-
/// these tests pass under `--test-threads=1` and fail in parallel.
23-
///
24-
/// Serialise the counter-asserting tests against each other. Tests that
25-
/// only assert on addresses and registry membership are thread-local and
26-
/// need no lock.
27-
fn counter_guard() -> std::sync::MutexGuard<'static, ()> {
28-
static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
29-
// A panicking test poisons the lock; the data is `()`, so recovering
30-
// is right — otherwise one failure cascades into spurious ones.
31-
LOCK.lock().unwrap_or_else(|e| e.into_inner())
32-
}
33-
3416
/// A released cell must be INERT: de-registered (reads `undefined`,
3517
/// writes dropped), evicted from the positive cache, and parked exactly
3618
/// once no matter how many times the terminal arm re-runs (#7933
@@ -463,7 +445,6 @@ fn typed_control_cells_park_terminal_values() {
463445
/// carries its own fresh value rather than a leftover link.
464446
#[test]
465447
fn the_intrusive_free_list_round_trips_a_whole_cohort() {
466-
let _guard = counter_guard();
467448
super::test_clear_box_registry();
468449
const N: usize = 512;
469450
let first: Vec<*mut Box> = (0..N)
@@ -477,19 +458,9 @@ fn the_intrusive_free_list_round_trips_a_whole_cohort() {
477458
}
478459
flush_released_boxes();
479460

480-
let (a0, r0, _) = box_release_stats();
481461
let second: Vec<*mut Box> = (0..N)
482462
.map(|i| js_box_alloc_bits((1000.0 + i as f64).to_bits() as i64))
483463
.collect();
484-
let (a1, r1, _) = box_release_stats();
485-
assert_eq!(a1 - a0, N as u64, "second cohort allocates N cells");
486-
assert_eq!(
487-
r1 - r0,
488-
N as u64,
489-
"ALL N must come from the free list; {} fell through to std::alloc",
490-
N as u64 - (r1 - r0)
491-
);
492-
493464
let reused: std::collections::HashSet<usize> = second.iter().map(|p| *p as usize).collect();
494465
assert_eq!(reused.len(), N, "an address was handed out twice");
495466
assert_eq!(
@@ -504,13 +475,13 @@ fn the_intrusive_free_list_round_trips_a_whole_cohort() {
504475
"cell {i} kept a stale free-list link instead of its value"
505476
);
506477
}
507-
// Drained: the next allocation has to mint.
508-
let before = box_release_stats().1;
509-
let _fresh = js_box_alloc_bits(0);
510-
assert_eq!(
511-
box_release_stats().1,
512-
before,
513-
"the list was drained, so this must be a fresh std::alloc"
478+
// The whole cohort is live again, so a drained list must mint a cell
479+
// outside it. Unlike the process-global telemetry counters, this address
480+
// check is isolated to the current thread's free list.
481+
let fresh = js_box_alloc_bits(0);
482+
assert!(
483+
!minted.contains(&(fresh as usize)),
484+
"the list was drained, so the next cell must be freshly minted"
514485
);
515486
}
516487

@@ -540,7 +511,6 @@ fn foreign_pointer_release_is_a_total_noop() {
540511
/// asyncpipe_big).
541512
#[test]
542513
fn completed_activation_residue_is_bounded_not_linear() {
543-
let _guard = counter_guard();
544514
super::test_clear_box_registry();
545515
const TURNS: usize = 100;
546516
const ACTIVATIONS_PER_TURN: usize = 20;

0 commit comments

Comments
 (0)