diff options
Diffstat (limited to 'src/simtest')
| -rw-r--r-- | src/simtest/holding.rs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 5d5cecf..0a40657 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -2270,6 +2270,108 @@ async fn a_node_of_both_kinds_carries_events_between_them() { assert!(e.doc.read().await.heads().is_empty()); } +/// A larger swarm on its way to sets of events, each node keeping two neighbours: a, b +/// and c hold the store in the Automerge document, m, n and o in both, e, f and g in a +/// set. The nodes of the one kind and of the other read different members' entries, and +/// so different neighbours; those of both read them all. An event put on a node of +/// either kind reaches all nine all the same, and so does one put while one of the +/// nodes of both kinds is down. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_larger_swarm_on_its_way_to_sets_passes_events_on_between_the_kinds() { + let sim = Sim::with_identity(100); + let (tv, lass, makefu) = three(); + let (_, root, id) = federation(&[ + (&tv, &["a", "b", "c"]), + (&lass, &["m", "n", "o"]), + (&makefu, &["e", "f", "g"]), + ]); + 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| { + config.neighbours_k = 2; + of_the_store(config, id, Some(&root), holding); + }, + ) + }; + let on_a_set = |name: &'static str, seeds: &'static [&'static str]| { + let root = root.clone(); + sim.start_with( + name, + seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.neighbours_k = 2; + 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 both = || holding("lass").of_both(Duration::from_secs(600)); + let nodes = [ + start("a", &[], holding("tv")), + start("b", &["a"], holding("tv")), + start("c", &["a"], holding("tv")), + start("m", &["a"], both()), + start("n", &["a"], both()), + start("o", &["a"], both()), + on_a_set("e", &["m"]), + on_a_set("f", &["n"]), + on_a_set("g", &["o"]), + ]; + let all: Vec<&AppState> = nodes.iter().collect(); + let all = &all; + sim.wait_ready(all, LONG).await; + sim.wait_until( + "the nodes holding sets hold each other's entries", + LONG, + move || async move { all[3..].iter().all(|node| entries(node) == 6) }, + ) + .await; + + let on_a = tv.write(&[id], "home/tv/x", s("1")); + let on_g = makefu.write(&[id], "home/makefu/y", s("2")); + let ids = [Id::of(&on_a), Id::of(&on_g)]; + put(all[0], &[&on_a]).await; + put(all[8], &[&on_g]).await; + let first = &ids; + sim.wait_until("all nine hold both events", LONG, move || async move { + all.iter().all(|node| holds(node, first)) + }) + .await; + + // One of the nodes of both kinds down: the others carry between the kinds. + sim.net.take_down("m"); + let on_c = tv.write(&[ids[0], ids[1]], "home/tv/z", s("3")); + let on_e = makefu.write(&[ids[0], ids[1]], "home/makefu/w", s("4")); + let later = [Id::of(&on_c), Id::of(&on_e)]; + put(all[2], &[&on_c]).await; + put(all[6], &[&on_e]).await; + let later = &later; + sim.wait_until( + "the eight that are up hold those too", + LONG, + move || async move { + all.iter() + .enumerate() + .all(|(at, node)| at == 3 || holds(node, later)) + }, + ) + .await; + sim.net.bring_up("m"); + sim.wait_until("and m, back, as well", LONG, move || async move { + holds(all[3], later) + }) + .await; +} + /// 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 |
