aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:22:36 +0000
committertv <tv@krebsco.de>2026-12-01 02:22:36 +0000
commit80a1075951bdf70a4e9fb68e4a4228cfe0d27ba8 (patch)
tree48a6b108589a3646a5ec1ff6997f2b2e06547a9e /src/simtest
parentd3c12b3951d4078ea8dda61a436d46cc85fa8f33 (diff)
remake: a node on a set of events follows no epoch
A node on a set alone, hearing peers of both kinds on a later epoch, rejoined it, and filled the Automerge document it holds beside its set with the snapshot: a set has no epochs, and that document stays empty. A simulation of a compaction while a swarm is on its way to sets: the nodes on the document and of both kinds switch, the node on a set stays, and events go on between them through the node of both.
Diffstat (limited to 'src/simtest')
-rw-r--r--src/simtest/holding.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index e6e2449..5cc9c21 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -2354,6 +2354,91 @@ async fn a_node_of_both_kinds_carries_events_between_them() {
assert!(e.doc.read().await.heads().is_empty());
}
+/// A compaction while a swarm is on its way to sets of events: a and b hold the store
+/// in the Automerge document, m in both, e in a set. a, b and m switch to the new
+/// document; e, which holds none, stays where it is. What was put before is held by all
+/// four after, and what is put on a and on e then reaches all four, through m.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_remake_while_a_swarm_is_on_its_way_to_sets() {
+ let sim = Sim::with_identity(103);
+ 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)),
+ );
+ let e = {
+ let root = root.clone();
+ sim.start_with(
+ "e",
+ &["m"],
+ 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;
+ let on_a = tv.write(&[id], "home/tv/x", s("1"));
+ let on_e = makefu.write(&[id], "home/makefu/y", s("2"));
+ let before = [Id::of(&on_a), Id::of(&on_e)];
+ put(&a, &[&on_a]).await;
+ put(&e, &[&on_e]).await;
+ let ids = &before;
+ sim.wait_until("all four hold both events", LONG, move || async move {
+ all.iter().all(|node| holds(node, ids))
+ })
+ .await;
+
+ compact(&a).await;
+ on_generation(
+ &sim,
+ &[a.clone(), b.clone(), m.clone()],
+ 1,
+ Duration::from_secs(60),
+ )
+ .await;
+ assert_eq!(e.local_epoch().generation, 0);
+ // The new document holds what e put, which m had put into the one before.
+ assert!(events::ids(&a.doc.read().await.doc).contains(&before[1]));
+
+ let then_a = tv.write(&before, "home/tv/x", s("3"));
+ let then_e = makefu.write(&before, "home/makefu/y", s("4"));
+ let after = [Id::of(&then_a), Id::of(&then_e)];
+ put(&a, &[&then_a]).await;
+ put(&e, &[&then_e]).await;
+ let ids = &after;
+ sim.wait_until(
+ "all four hold what was put after the switch",
+ LONG,
+ move || async move { all.iter().all(|node| holds(node, ids)) },
+ )
+ .await;
+ let read: Vec<Option<Counts>> = all.iter().map(|node| counts(node)).collect();
+ assert!(read.iter().all(|counts| counts == &read[0]), "{read:?}");
+ 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