diff options
| author | tv <tv@krebsco.de> | 2026-12-01 02:45:46 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 02:45:46 +0100 |
| commit | 34bfcb661ed74bf40809576bbb388362cb7ffaa1 (patch) | |
| tree | 8422db7db396dd4ae83403837cd954a94f882a7a /src/simtest | |
| parent | 34434f7fd5a6bab1884a63c96679f48045f4bffd (diff) | |
| parent | 6a06bc4a955cdf2b5a183c9ff21e25c79a4e5d9f (diff) | |
Diffstat (limited to 'src/simtest')
| -rw-r--r-- | src/simtest/holding.rs | 678 |
1 files changed, 678 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 16158b1..8f601dd 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -1726,3 +1726,681 @@ async fn store_attack_31() { ) .await; } + +/// A store carried by a set of events on `root`, for a node of `party`. +fn of_a_set(party: &str, root: &[u8]) -> Holding { + use crate::federation::store::set::Set; + holding(party).carrying(Set::new( + Store::<Federation>::new(root.to_vec(), Vec::new()).expect("a root"), + Duration::from_secs(600), + )) +} + +/// How many members' entries `node`'s set holds. +fn entries(node: &AppState) -> usize { + node.holding + .with_set(|set| set.entries().count()) + .unwrap_or(0) +} + +/// Where `node`'s set stands. +fn stands(node: &AppState) -> Option<crate::federation::store::passing::Stamp> { + node.holding + .with_set(crate::federation::store::passing::stamp) +} + +/// tv lists a and b, lass lists c: each node's store is carried by a set of events, +/// its own document, and nothing is in the Automerge document it holds. Each registers, +/// and its entry reaches the others; events put on a and on c reach all three; and they +/// come to stand alike. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_swarm_of_sets_passes_entries_and_events_on() { + let sim = Sim::with_identity(91); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["c"])]); + let nodes: Vec<AppState> = [("a", "tv"), ("b", "tv"), ("c", "lass")] + .into_iter() + .map(|(name, party)| { + let seeds: Vec<&str> = if name == "a" { Vec::new() } else { vec!["a"] }; + let root = root.clone(); + sim.start_with( + name, + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = of_a_set(party, &root); + }, + ) + }) + .collect(); + let members: Vec<&AppState> = nodes.iter().collect(); + let members = &members; + sim.wait_ready(members, SOON).await; + for node in members.iter() { + assert_eq!(node.kinds(), [crate::federation::store::set::KIND]); + assert!(node.holding.tells_members()); + } + sim.wait_until("each holds the three entries", SOON, move || async move { + members.iter().all(|node| entries(node) == 3) + }) + .await; + + let on_a = tv.write(&[id], "home/tv/x", s("1")); + let on_c = lass.write(&[id], "home/lass/y", s("2")); + let ids = [Id::of(&on_a), Id::of(&on_c)]; + put(members[0], &[&on_a]).await; + put(members[2], &[&on_c]).await; + sim.wait_until("a, b and c hold both events", SOON, move || async move { + members.iter().all(|node| holds(node, &ids)) + }) + .await; + sim.wait_until("they stand alike", SOON, move || async move { + let first = stands(members[0]); + first.is_some() && members.iter().all(|node| stands(node) == first) + }) + .await; + for node in members.iter() { + assert_eq!(read(node, |store| store.state().values().len()), Some(2)); + // Nothing went into the document it holds beside. + assert!(node.doc.read().await.heads().is_empty()); + } +} + +/// On sets of events, a version of a federation this continuum doesn't know passes, and +/// a version event writes it: every node stops there. What is put through one of them +/// meanwhile, it holds back and passes on, as it can't tell what will be taken: the +/// others hold it back too. Their operators have them drop that event: they take again, +/// all alike. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_stopped_node_of_a_set_passes_on_what_it_holds_back() { + let sim = Sim::with_identity(99); + let (tv, lass, makefu) = three(); + let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]); + let nodes: Vec<AppState> = [("a", "tv"), ("b", "lass"), ("c", "makefu")] + .into_iter() + .map(|(name, party)| { + let seeds: Vec<&str> = if name == "a" { Vec::new() } else { vec!["a"] }; + let root = root.clone(); + sim.start_with( + name, + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = of_a_set(party, &root); + }, + ) + }) + .collect(); + let members: Vec<&AppState> = nodes.iter().collect(); + let all = &members; + sim.wait_ready(all, SOON).await; + sim.wait_until("each holds the three entries", SOON, move || async move { + all.iter().all(|node| entries(node) == 3) + }) + .await; + + let on = first.hash(); + let text = String::from_utf8(first.after(on).json().bytes()) + .expect("UTF-8") + .replace(r#""federation":1"#, r#""federation":2"#); + let unknown = crate::federation::jcs::read(text.as_bytes()).expect("JCS"); + let hash = Id::of(&unknown.bytes()); + let proposal = tv.propose(&[id], &unknown); + let votes = [&tv, &lass].map(|party| party.vote(&[Id::of(&proposal)], on, hash, true)); + let written = harness::version_event(&[Id::of(&votes[0]), Id::of(&votes[1])], hash); + let at = Id::of(&written); + put(all[0], &[&proposal, &votes[0], &votes[1], &written]).await; + sim.wait_until("every node stopped there", LONG, move || async move { + all.iter().all(|node| stopped(node) == Some(at)) + }) + .await; + + let meanwhile = tv.write(&[id], "home/tv/a", s("1")); + put(all[0], &[&meanwhile]).await; + let meanwhile = Id::of(&meanwhile); + sim.wait_until("every node holds it back", LONG, move || async move { + all.iter() + .all(|node| holds_back(node, &[at, meanwhile], false)) + }) + .await; + + for node in all.iter() { + let dropped = node.holding.drop_taken(&[at]).expect("a store"); + assert_eq!(dropped, Ok(vec![at])); + } + sim.wait_until("every node takes again", LONG, move || async move { + all.iter() + .all(|node| stopped(node).is_none() && holds(node, &[meanwhile])) + }) + .await; + let read: Vec<Option<Counts>> = all.iter().map(|node| counts(node)).collect(); + assert!(read.iter().all(|counts| counts == &read[0]), "{read:?}"); +} + +/// Starts `name`, of `party`, on a set of events `set`, kept in the file at `path` where +/// given: the first of them with no seed, the others seeded by `a`. +fn start_on_a_set( + sim: &Sim, + name: &str, + party: &str, + id: Id, + set: crate::federation::store::set::Set<Federation>, + path: Option<std::path::PathBuf>, + restart: bool, +) -> AppState { + let seeds: Vec<&str> = if name == "a" { Vec::new() } else { vec!["a"] }; + let party = party.to_owned(); + let adjust = move |config: &mut NodeConfig| { + config.store = Some(id); + config.holding = holding(&party).carrying_if( + Some(held::Begun::Set(Box::new(set))), + path, + Arc::new(Files::default()), + ); + }; + if restart { + sim.restart_with(name, &seeds, Start::FromDocument(Origin::Root), adjust) + } else { + sim.start_with(name, &seeds, Start::FromDocument(Origin::Root), adjust) + } +} + +/// A set of events begun from `root`. +fn a_set(root: &[u8]) -> crate::federation::store::set::Set<Federation> { + crate::federation::store::set::Set::new( + Store::<Federation>::new(root.to_vec(), Vec::new()).expect("a root"), + Duration::from_secs(600), + ) +} + +/// a and b hold events; c, of another party, starts later from the root alone, and +/// catches up: it comes to hold what they hold, and to stand as they do. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_a_set_that_is_behind_catches_up() { + let sim = Sim::with_identity(92); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["c"])]); + let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false); + let b = start_on_a_set(&sim, "b", "tv", id, a_set(&root), None, false); + sim.wait_ready(&[&a, &b], SOON).await; + // A chain of writes, each on the one before. + let mut on = id; + let mut ids = Vec::new(); + for n in 0..30 { + let write = tv.write(&[on], "home/tv/x", s(&n.to_string())); + on = Id::of(&write); + ids.push(on); + put(&a, &[&write]).await; + } + let (first, ids) = (&[&a, &b], &ids); + sim.wait_until("a and b hold the writes", SOON, move || async move { + first.iter().all(|node| holds(node, ids)) + }) + .await; + + let c = start_on_a_set(&sim, "c", "lass", id, a_set(&root), None, false); + let all = &[&a, &b, &c]; + sim.wait_until("c holds them too", SOON, move || async move { + holds(all[2], ids) + }) + .await; + sim.wait_until("all stand alike", SOON, move || async move { + let first = stands(all[0]); + first.is_some() && all.iter().all(|node| stands(node) == first) && entries(all[2]) == 3 + }) + .await; +} + +/// A node keeps its set in a file, written as the set changes; started again on what +/// the file holds, it holds what it held, the others' entries among it, before it hears +/// of anyone. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_a_set_goes_on_from_its_file() { + let sim = Sim::with_identity(93); + let (tv, _, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"])]); + let dir = crate::files::scratch_dir("set-file"); + let path = dir.join("b.events"); + let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false); + let b = start_on_a_set(&sim, "b", "tv", id, a_set(&root), Some(path.clone()), false); + sim.wait_ready(&[&a, &b], SOON).await; + let write = tv.write(&[id], "home/tv/x", s("1")); + let ids = [Id::of(&write)]; + put(&a, &[&write]).await; + let (nodes, ids) = (&[&a, &b], &ids); + sim.wait_until( + "both hold the write and both entries", + SOON, + move || async move { + nodes + .iter() + .all(|node| holds(node, ids) && entries(node) == 2) + }, + ) + .await; + assert!(b.holding.save().expect("written") || path.exists()); + + let bytes = std::fs::read(&path).expect("the set's file"); + let set = crate::federation::store::set::Set::<Federation>::load( + &bytes, + Duration::from_secs(600), + std::time::Instant::now(), + ) + .expect("a set"); + let b = start_on_a_set(&sim, "b", "tv", id, set, Some(path), true); + // What the file held, at once. + assert!(holds(&b, ids)); + assert_eq!(entries(&b), 2); + // And it goes on: a write put on it reaches a. + sim.wait_ready(&[&b], SOON).await; + let next = tv.write(&[ids[0]], "home/tv/x", s("2")); + let next_id = [Id::of(&next)]; + put(&b, &[&next]).await; + let (a, next_id) = (&a, &next_id); + sim.wait_until("a holds what b wrote after", SOON, move || async move { + holds(a, next_id) + }) + .await; +} + +/// a and b hold the store and a write; c is given the store's ID alone, and nothing of +/// the store: it asks the members it reaches for the root by its name, begins its set +/// from it, and catches up as any node behind. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_a_set_joins_with_nothing_but_the_stores_id() { + use crate::federation::store::passing; + + let sim = Sim::with_identity(94); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["c"])]); + let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false); + let b = start_on_a_set(&sim, "b", "tv", id, a_set(&root), None, false); + sim.wait_ready(&[&a, &b], SOON).await; + let write = tv.write(&[id], "home/tv/x", s("1")); + let ids = [Id::of(&write)]; + put(&a, &[&write]).await; + + let c = sim.start_with( + "c", + &["a"], + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding("lass").carrying_if( + Some(held::Begun::Start(passing::Start::new( + id, + id, + Duration::from_secs(600), + ))), + None, + Arc::new(Files::default()), + ); + }, + ); + assert_eq!(c.kinds(), [crate::federation::store::set::KIND]); + assert!(read(&c, |_| ()).is_none()); + sim.wait_ready(&[&c], SOON).await; + let (all, ids) = (&[&a, &b, &c], &ids); + sim.wait_until( + "c holds the store, the write and the entries", + SOON, + move || async move { holds(all[2], ids) && all.iter().all(|node| entries(node) == 3) }, + ) + .await; + sim.wait_until("all stand alike", SOON, move || async move { + let first = stands(all[0]); + first.is_some() && all.iter().all(|node| stands(node) == first) + }) + .await; +} + +/// d is of lass, which doesn't list it: given the store's ID, it reaches a, which takes +/// none of its handshakes and gives it nothing, neither the root nor an event. It never +/// holds the store. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_no_party_lists_gets_nothing_of_a_set() { + use crate::federation::store::passing; + + let sim = Sim::with_identity(95); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["c"])]); + let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false); + let b = start_on_a_set(&sim, "b", "tv", id, a_set(&root), None, false); + sim.wait_ready(&[&a, &b], SOON).await; + let write = tv.write(&[id], "home/tv/x", s("1")); + put(&a, &[&write]).await; + let pair = &[&a, &b]; + sim.wait_until( + "a and b hold each other's entries", + SOON, + move || async move { pair.iter().all(|node| entries(node) == 2) }, + ) + .await; + + let d = sim.start_with( + "d", + &["a"], + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding("lass").carrying_if( + Some(held::Begun::Start(passing::Start::new( + id, + id, + Duration::from_secs(600), + ))), + None, + Arc::new(Files::default()), + ); + }, + ); + // Long enough for it to have joined, were it let in. + tokio::time::sleep(Duration::from_secs(4)).await; + assert!(!d.is_ready().await); + assert!(read(&d, |_| ()).is_none()); + assert!(!d.holding.start_wants().is_empty()); + // And a holds no entry of it. + assert_eq!(entries(&a), 2); +} + +/// A node away while the others moved to a checkpoint: a and b forgot what came before +/// it, and keep it a while beside their stores; c, back, gets that of them, builds the +/// checkpoint itself, and reads what they read, what came after it too. d, with nothing +/// and the checkpoint pinned, begins from it by its name. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_a_set_away_across_a_move_builds_the_checkpoint_itself() { + use crate::federation::store::passing; + + let sim = Sim::with_identity(96); + let parties = three(); + let (tv, lass, makefu) = &parties; + let (first, root, id) = federation(&[(tv, &["a"]), (lass, &["b"]), (makefu, &["c", "d"])]); + let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false); + let b = start_on_a_set(&sim, "b", "lass", id, a_set(&root), None, false); + let c = start_on_a_set(&sim, "c", "makefu", id, a_set(&root), None, false); + let all = &[&a, &b, &c]; + sim.wait_ready(all, SOON).await; + sim.wait_until("each holds the three entries", SOON, move || async move { + all.iter().all(|node| entries(node) == 3) + }) + .await; + + sim.net.take_down("c"); + let gone = tv.write(&[id], "home/tv/a", s("0")); + let head = tv.write(&[Id::of(&gone)], "home/tv/a", s("1")); + let (next, [proposal, tv_yes, lass_yes]) = checkpoint_at(&parties, &first, &[Id::of(&head)]); + put(&a, &[&gone, &head, &proposal, &tv_yes]).await; + put(&b, &[&lass_yes]).await; + let passed = next.hash(); + sim.wait_until( + "a and b moved to the checkpoint", + LONG, + move || async move { + all[..2] + .iter() + .all(|node| current(node) == Some(passed) && checkpoint(node) != Some(id)) + }, + ) + .await; + let after = tv.write(&[Id::of(&head)], "home/tv/b", s("2")); + put(&a, &[&after]).await; + let moved = checkpoint(&a).expect("a store"); + assert_eq!(checkpoint(&b), Some(moved)); + let gone = Id::of(&gone); + // The store forgot it; the set keeps it a while, for whoever is still before. + assert_eq!(read(&a, |store| store.get(&gone).is_some()), Some(false)); + assert_eq!( + a.holding.with_set(|set| set.get(&gone).is_some()), + Some(true) + ); + + sim.net.bring_up("c"); + let after = Id::of(&after); + sim.wait_until( + "c moved there, and holds what came after", + LONG, + move || async move { + checkpoint(all[2]) == Some(moved) && holds(all[2], &[after]) && holds(all[1], &[after]) + }, + ) + .await; + assert_eq!(counts(&c), counts(&a)); + + let d = sim.start_with( + "d", + &["a"], + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding("makefu").carrying_if( + Some(held::Begun::Start(passing::Start::new( + id, + moved, + Duration::from_secs(600), + ))), + None, + Arc::new(Files::default()), + ); + }, + ); + sim.wait_ready(&[&d], SOON).await; + let d = &d; + sim.wait_until( + "d began from the pinned checkpoint, and caught up", + LONG, + move || async move { checkpoint(d) == Some(moved) && holds(d, &[after]) }, + ) + .await; + assert_eq!(counts(d), counts(&a)); +} + +/// A swarm on its way from Automerge documents to sets of events: a and b hold the +/// store in the Automerge document, e in a set, and m in both. a and e take none of +/// each other's handshakes; m takes both, saying to each the kind it holds. An event +/// put on a reaches e through m, and one put on e reaches a and b: m takes into each +/// what the other holds. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_node_of_both_kinds_carries_events_between_them() { + let sim = Sim::with_identity(97); + let (tv, lass, makefu) = three(); + let (_, root, id) = federation(&[(&tv, &["a", "b"]), (&lass, &["m"]), (&makefu, &["e"])]); + let start = |name: &'static str, seeds: &'static [&'static str], holding: Holding| { + let root = root.clone(); + sim.start_with( + name, + seeds, + Start::FromDocument(Origin::Root), + move |config| { + of_the_store(config, id, Some(&root), holding); + }, + ) + }; + let a = start("a", &[], holding("tv")); + let b = start("b", &["a"], holding("tv")); + let m = start( + "m", + &["a"], + holding("lass").of_both(Duration::from_secs(600)), + ); + assert_eq!(m.kinds().len(), 2); + let e = { + let seeds = ["m"]; + let root = root.clone(); + sim.start_with( + "e", + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding("makefu").carrying_if( + Some(held::Begun::Set(Box::new(a_set(&root)))), + None, + Arc::new(Files::default()), + ); + }, + ) + }; + let all = &[&a, &b, &m, &e]; + sim.wait_ready(all, SOON).await; + sim.wait_until( + "m holds a set, and its entry and e's in it", + LONG, + move || async move { entries(all[2]) == 2 && entries(all[3]) == 2 }, + ) + .await; + + let on_a = tv.write(&[id], "home/tv/x", s("1")); + let on_e = makefu.write(&[id], "home/makefu/y", s("2")); + let ids = [Id::of(&on_a), Id::of(&on_e)]; + put(&a, &[&on_a]).await; + put(&e, &[&on_e]).await; + let ids = &ids; + sim.wait_until("all four hold both events", LONG, move || async move { + all.iter().all(|node| holds(node, ids)) + }) + .await; + for node in all.iter() { + assert_eq!(read(node, |store| store.state().values().len()), Some(2)); + } + // e's event is in the Automerge document, which m put it in; a's isn't in e's, which + // holds nothing. + assert!(events::ids(&a.doc.read().await.doc).contains(&ids[1])); + assert!(e.doc.read().await.heads().is_empty()); +} + +/// A swarm moves from Automerge documents to sets of events, node by node, as its +/// operators are told to: a and b on the document; then each of both kinds, started +/// again on its document with a file for its set; then each on its set alone, started +/// again from that file. What was put before is held throughout, and what is put at +/// each step reaches the other node. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_swarm_moves_to_sets_node_by_node() { + use crate::federation::store::set::Set; + + let sim = Sim::with_identity(98); + let (tv, lass, _) = three(); + let (_, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"])]); + let dir = crate::files::scratch_dir("move-to-sets"); + let keeps = Duration::from_secs(600); + let nodes = started( + &sim, + &root, + vec![("a", holding("tv")), ("b", holding("lass"))], + ) + .await; + let (mut a, mut b) = (nodes[0].clone(), nodes[1].clone()); + let x = tv.write(&[id], "home/tv/x", s("1")); + put(&a, &[&x]).await; + let mut ids = vec![Id::of(&x)]; + { + let (pair, ids) = (&[&a, &b], &ids); + sim.wait_until("both hold x", LONG, move || async move { + pair.iter().all(|node| holds(node, ids)) + }) + .await; + } + + // Each of both kinds, on the document it has. + for (name, party, seeds) in [("a", "tv", [""; 0].as_slice()), ("b", "lass", &["a"])] { + let node = if name == "a" { &a } else { &b }; + let doc = node.doc.read().await.doc.clone(); + let path = dir.join(format!("{name}.events")); + let party = party.to_owned(); + let again = sim.restart_with( + name, + seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.initial_doc = doc; + config.holding = holding(&party).of_both(keeps).carrying_if( + None, + Some(path), + Arc::new(Files::default()), + ); + }, + ); + sim.wait_ready(&[&again], SOON).await; + { + let (again, ids) = (&again, &ids); + sim.wait_until("it made its set, holding what it held", LONG, move || async move { + again.holding.with_set(|_| ()).is_some() && holds(again, ids) + }) + .await; + } + if name == "a" { + a = again; + } else { + b = again; + } + } + let y = lass.write(&[ids[0]], "home/lass/y", s("2")); + put(&b, &[&y]).await; + ids.push(Id::of(&y)); + { + let (pair, ids) = (&[&a, &b], &ids); + sim.wait_until( + "both hold y, and each other's entry in their sets", + LONG, + move || async move { + pair.iter() + .all(|node| holds(node, ids) && entries(node) == 2) + }, + ) + .await; + } + + // Each on its set alone, from the set's file. + for (name, party, seeds) in [("a", "tv", [""; 0].as_slice()), ("b", "lass", &["a"])] { + let node = if name == "a" { &a } else { &b }; + node.holding.save().expect("the set written"); + let path = dir.join(format!("{name}.events")); + let bytes = std::fs::read(&path).expect("the set's file"); + let set = Set::<Federation>::load(&bytes, keeps, std::time::Instant::now()).expect("a set"); + let party = party.to_owned(); + let again = sim.restart_with( + name, + seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = holding(&party).carrying_if( + Some(held::Begun::Set(Box::new(set))), + Some(path), + Arc::new(Files::default()), + ); + }, + ); + assert_eq!(again.kinds(), [crate::federation::store::set::KIND]); + assert!(holds(&again, &ids), "what the file held"); + sim.wait_ready(&[&again], SOON).await; + let z = tv.write( + &[*ids.last().expect("some")], + &format!("home/tv/{name}"), + s("3"), + ); + put(&again, &[&z]).await; + ids.push(Id::of(&z)); + if name == "a" { + a = again; + } else { + b = again; + } + let (pair, ids) = (&[&a, &b], &ids); + sim.wait_until( + "both hold what was put on the one started again", + LONG, + move || async move { pair.iter().all(|node| holds(node, ids)) }, + ) + .await; + } + assert!(a.doc.read().await.heads().is_empty()); + assert_eq!(read(&a, |store| store.state().values().len()), Some(4)); + let pair = &[&a, &b]; + sim.wait_until("they stand alike", LONG, move || async move { + stands(pair[0]).is_some() && stands(pair[0]) == stands(pair[1]) + }) + .await; +} |
