aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest/holding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/simtest/holding.rs')
-rw-r--r--src/simtest/holding.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 0841a75..120c6da 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -2123,3 +2123,77 @@ async fn a_node_of_a_set_away_across_a_move_builds_the_checkpoint_itself() {
.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());
+}