aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 04:16:12 +0000
committertv <tv@krebsco.de>2026-11-20 05:29:48 +0100
commit7926a9764626878f5cc244286cce9eb502358929 (patch)
tree7ba6082872afd464490feb296c4f54afbc5c80a9 /src/simtest
parent00cac6466057c2a8a92dae9e4cd46369e72bcad9 (diff)
keep-actor by default: the writer kept across a clean stop, writes held till a sync
A node that stopped cleanly writes on as the writer of before, as `--keep-actor` had it, now by default: an epoch gathers a writer per node and per crash, drop or rejoin, not per start. `keep-actor = false`, in a configuration file, has a node write as a fresh writer each start; a node without a document file has nothing to keep, which is no longer an error. Writing on as the writer of before, a node holds its writes (`mutate_doc` and the API's through it) until it synced once with a ready neighbour, level with it, or 10 seconds passed (`AppState::hold_writes`, `KEPT_WRITER_WAIT`): a neighbour holding later changes of that writer, which a copy of the node's files made (a backup restored, a disk rolled back), hands them over first, and the node takes a fresh writer then, as it did. A node that reaches no neighbour within the wait writes on.
Diffstat (limited to 'src/simtest')
-rw-r--r--src/simtest/signatures.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/simtest/signatures.rs b/src/simtest/signatures.rs
index b65b3a7..cc087a9 100644
--- a/src/simtest/signatures.rs
+++ b/src/simtest/signatures.rs
@@ -110,3 +110,38 @@ async fn a_signed_write_vouches_for_the_writes_before() {
.await;
}
}
+
+/// A node writing on as its writer of before holds its writes until it synced once with a
+/// ready neighbour (`AppState::hold_writes`): a write waits while the node is alone, and
+/// goes once a neighbour came and the node is level with it, before the wait ran out.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_kept_writer_writes_once_it_synced_with_a_neighbour() {
+ let sim = Sim::new(62);
+ let a = sim.start("a", &[], Start::Genesis);
+ sim.wait_ready(&[&a], SOON).await;
+ a.hold_writes();
+ let writing = tokio::spawn({
+ let a = a.clone();
+ async move { super::write(&a, "users/alice", json!(1)).await }
+ });
+ tokio::time::sleep(Duration::from_secs(1)).await;
+ assert!(*a.writes_held.borrow(), "writes go while alone");
+ assert!(
+ !writing.is_finished(),
+ "a write went while writes were held"
+ );
+
+ let b = sim.start("b", &["a"], Start::Join);
+ sim.wait_until(
+ "a synced with b",
+ crate::state::KEPT_WRITER_WAIT - Duration::from_secs(2),
+ || async { !*a.writes_held.borrow() },
+ )
+ .await;
+ tokio::time::timeout(SOON, writing)
+ .await
+ .expect("the write went")
+ .expect("the write task");
+ sim.wait_converged(&[&a, &b], SOON).await;
+ assert_eq!(super::read(&b, "users/alice").await, Some(json!(1)));
+}