test(causal): controller test no longer races the sweep's site snapshot

run_experiments snapshots the site registry once at entry. stage-x is
registered lazily (first causal_site! execution in the worker), so on a
1-core box the snapshot deterministically wins whenever a sibling test
has already paid the tsc_hz calibration — stage-x missed the sweep and
the summary assert tripped (silently, pre-propagation; the earlier
cascade attribution was incomplete). The worker now signals after its
first site entry and the test waits on it before starting the sweep.
Jarred separately: the lazy-registration trap is a lib UX hazard worth a
doc note or warm-up guidance.
This commit is contained in:
Claude (sandbox)
2026-07-18 21:59:21 +00:00
parent d5a3ba1934
commit d9addeba5e
+11
View File
@@ -310,7 +310,14 @@ fn controller_produces_report() {
smarm::init(smarm::Config::exact(2)).run(|| { smarm::init(smarm::Config::exact(2)).run(|| {
let stop = Arc::new(AtomicBool::new(false)); let stop = Arc::new(AtomicBool::new(false));
let stop2 = stop.clone(); let stop2 = stop.clone();
// run_experiments snapshots the site registry once at entry; the
// worker must have executed its first `causal_site!` (lazy
// registration) before the call, or stage-x misses the sweep — a
// race this test loses deterministically on a 1-core box whenever a
// sibling test has already paid the tsc_hz calibration.
let (ready_tx, ready_rx) = smarm::channel::<()>();
let worker = smarm::spawn(move || { let worker = smarm::spawn(move || {
let mut ready = Some(ready_tx);
while !stop2.load(Ordering::Relaxed) { while !stop2.load(Ordering::Relaxed) {
{ {
let _g = smarm::causal_site!("stage-x"); let _g = smarm::causal_site!("stage-x");
@@ -319,8 +326,12 @@ fn controller_produces_report() {
} }
} }
smarm::progress!("items"); smarm::progress!("items");
if let Some(tx) = ready.take() {
let _ = tx.send(());
}
} }
}); });
ready_rx.recv().unwrap();
let results = smarm::causal::run_experiments(&smarm::causal::ExperimentPlan { let results = smarm::causal::run_experiments(&smarm::causal::ExperimentPlan {
speedups_pct: vec![0, 50], speedups_pct: vec![0, 50],