frame tests: last good cleared by delete and switch, kept through a frame error; switch releases binder interests; tombstone replay; more seeds

This commit is contained in:
Meta Vens 2026-11-28 09:34:15 +01:00
commit bae8cbbb14

View file

@ -345,9 +345,19 @@ fn random_node(next: &mut dyn FnMut() -> u64, id: &mut u32, depth: u32) -> Node
Node::Box(node)
}
/// Fixed seeds for reproducibility, plus `THING_FRAME_SEED` when set; a failure names its seed.
#[test]
fn random_documents_and_inputs_never_panic_and_the_frame_is_deterministic() {
let mut seed = 0x9E37_79B9_7F4A_7C15u64;
let mut seeds = vec![0x9E37_79B9_7F4A_7C15u64, 0xD1B5_4A32_D192_ED03, 0x2545_F491_4F6C_DD1D, 7];
if let Some(extra) = std::env::var("THING_FRAME_SEED").ok().and_then(|v| v.parse().ok()) {
seeds.push(extra);
}
for seed in seeds {
random_run(seed);
}
}
fn random_run(mut seed: u64) {
let mut next = move || {
seed ^= seed << 13;
seed ^= seed >> 7;
@ -360,7 +370,7 @@ fn random_documents_and_inputs_never_panic_and_the_frame_is_deterministic() {
let (mut left, mut right) = (fresh(metrics), fresh(metrics));
let (mut left_state, mut right_state) = (MemState::new(), MemState::new());
let mut shown = false;
for round in 0..120i64 {
for round in 0..200i64 {
if next() % 9 != 0 {
let mut id = 0;
let document = inline(round + 1, random_node(&mut next, &mut id, 4));
@ -382,7 +392,99 @@ fn random_documents_and_inputs_never_panic_and_the_frame_is_deterministic() {
let frame = FrameInput { now: Timestamp(round), viewport: room, scale, events };
let one = run(&mut left, &mut left_state, frame.clone());
let two = run(&mut right, &mut right_state, frame);
assert_eq!(one, two, "round {round} in {metrics:?} at {room:?} scale {scale}");
assert_eq!(one, two, "seed {seed} round {round} in {metrics:?} at {room:?} scale {scale}");
}
}
}
fn wide(version: i64) -> SurfaceDocument {
let slab = |id: &str| match boxed(id, vec![]) {
Node::Box(mut slab) => {
slab.style.size = size2(px(1_500_000.0), px(10.0));
Node::Box(slab)
}
other => other,
};
let mut document = inline(version, boxed("root", vec![slab("left"), slab("right")]));
if let Node::Box(root) = &mut document.root {
root.style.direction = Direction::Row;
}
document
}
#[test]
fn the_last_good_frame_is_cleared_by_a_delete_and_a_switch_and_kept_through_a_frame_error() {
let at = (800.0, 600.0);
let good = say(1, "fits");
// Kept through a room with no size: a refused layout afterwards still shows it.
let mut state = MemState::new();
state.put(&good.provider_id, &good);
let mut one = fresh(Metrics::Pixels);
show(&mut one, &good);
let first = run(&mut one, &mut state, input(at, 1.0));
run(&mut one, &mut state, input((f32::NAN, 600.0), 1.0));
state.put(&good.provider_id, &wide(2));
let held = run(&mut one, &mut state, input(at, 1.0));
assert_eq!(held.commands, first.commands);
assert_eq!(codes(&held), vec![Code::LayoutOutOfRange]);
// Cleared by a delete: what comes after has no frame to fall back on.
let mut state = MemState::new();
state.put(&good.provider_id, &good);
let mut two = fresh(Metrics::Pixels);
show(&mut two, &good);
run(&mut two, &mut state, input(at, 1.0));
state.delete(&surface_address(&good));
assert_eq!(run(&mut two, &mut state, input(at, 1.0)).commands, vec![]);
// The tombstone keeps the version: the same document again, and a different one at it, change nothing shown.
state.put(&good.provider_id, &good);
let replay = run(&mut two, &mut state, input(at, 1.0));
assert_eq!((replay.commands, codes(&replay)), (vec![], vec![]));
state.put(&good.provider_id, &say(1, "other"));
let refused = run(&mut two, &mut state, input(at, 1.0));
assert_eq!((refused.commands, codes(&refused)), (vec![], vec![Code::StaleVersionIgnored]));
state.put(&good.provider_id, &wide(2));
let out = run(&mut two, &mut state, input(at, 1.0));
assert_eq!((out.commands, codes(&out)), (vec![], vec![Code::LayoutOutOfRange]));
// Cleared by a switch.
let other = {
let mut other = wide(1);
other.label = seg("other");
other
};
let mut state = MemState::new();
state.put(&good.provider_id, &good);
state.put(&other.provider_id, &other);
let mut three = fresh(Metrics::Pixels);
show(&mut three, &good);
run(&mut three, &mut state, input(at, 1.0));
show(&mut three, &other);
let switched = run(&mut three, &mut state, input(at, 1.0));
assert_eq!((switched.commands, codes(&switched)), (vec![], vec![Code::LayoutOutOfRange]));
}
#[test]
fn a_switch_leaves_the_old_surface_holding_no_interest() {
let swarm = Fixture::F01SwarmDashboard.load().surfaces.remove(0);
let other = say(1, "elsewhere");
let mut state = world(Fixture::F01SwarmDashboard);
state.put(&other.provider_id, &other);
let mut core = fresh(Metrics::Cells);
let at = (100.0, 37.0);
show(&mut core, &swarm);
run(&mut core, &mut state, input(at, 1.0));
let subscribed = count(&state, |call| matches!(call, Call::Subscribe(_)));
assert!(subscribed > 1, "f01 binds provider state, so more than its own record is held");
show(&mut core, &other);
run(&mut core, &mut state, input(at, 1.0));
let subscribes = count(&state, |call| matches!(call, Call::Subscribe(_)));
let unsubscribes = count(&state, |call| matches!(call, Call::Unsubscribe(_)));
assert_eq!(subscribes - unsubscribes, 1, "only the shown surface's own record is held");
// A record the old surface read now changes nothing and costs no read.
let summary = Swarm { id: "summary".into(), name: "Swarm".into(), load: 0.5 };
state.put_state(&ProviderId::new("provider.swarm"), "summary", &summary);
let before = state.calls().len();
run(&mut core, &mut state, input(at, 1.0));
assert_eq!(state.calls()[before..], [Call::Drain]);
}