diff options
| author | tv <tv@krebsco.de> | 2026-11-30 17:57:55 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 17:57:55 +0000 |
| commit | 08ec65219991c7413c8cdef4ce77434f2a121331 (patch) | |
| tree | 2c9d6f07e435a1ae37c62571579b170374cfbb70 /src/simtest | |
| parent | 00e88cd983766abec32b5a14a8cbf20932a27f3c (diff) | |
A node of both kinds, for a swarm to move to sets by (--store-both)
With store-document, store-both has the node hold its store in the
Automerge document too, and sync with nodes of either kind:
* it says to each peer the kind that peer holds, and passes its set on
to those that hold sets (swarm::set::holds_a_set), the Automerge
document to the others;
* what its set takes of the document goes on to the peers on sets
(Holding::unpassed), and what its set takes of them is put into the
document, as events it lacks are (Holding::lacking);
* its entry in the document is put as its entry in the set
(swarm::set::mirror_entry), and it reads the members of both;
* without the set's file yet, its set is made of the store as it reads
it of its document, with what store-file kept of its own.
A simulation: two nodes on the Automerge document, one on a set, one
of both between them; an event put on either side reaches all four.
Diffstat (limited to 'src/simtest')
| -rw-r--r-- | src/simtest/holding.rs | 74 |
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()); +} |
