aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 19:57:54 +0100
committertv <tv@krebsco.de>2026-11-01 19:57:54 +0100
commit7993cdfe8f8e24b39091b10a0a1bd45d66e3ccd8 (patch)
tree252af9493cb63f4acdfdbf7fac3b3b6ad871fbcc /src/simtest/mod.rs
parent541d1444efc4150ad3e644c7c262f51a4a26c0bb (diff)
add restart tests
Diffstat (limited to 'src/simtest/mod.rs')
-rw-r--r--src/simtest/mod.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/simtest/mod.rs b/src/simtest/mod.rs
index 81bddb5..61c81d1 100644
--- a/src/simtest/mod.rs
+++ b/src/simtest/mod.rs
@@ -144,6 +144,30 @@ impl Sim {
}
}
+impl Sim {
+ /// Restarts node `id`: its process is gone, as if it crashed (`SimNet::restart`:
+ /// what it still sends is lost), and a new one starts on the same ID, as
+ /// [`start_with`](Self::start_with) starts one. Nothing carries over but what
+ /// `adjust` gives it (its node key, under the identity layer, by its name).
+ pub(crate) fn restart_with(
+ &self,
+ id: &str,
+ seeds: &[&str],
+ start: Start,
+ adjust: impl FnOnce(&mut NodeConfig),
+ ) -> AppState {
+ {
+ let mut nodes = self.nodes.lock().unwrap();
+ for (_, old) in nodes.iter().filter(|(name, _)| name == id) {
+ old.closing.send_replace(true);
+ }
+ nodes.retain(|(name, _)| name != id);
+ }
+ self.net.restart(id);
+ self.start_with(id, seeds, start, adjust)
+ }
+}
+
/// Logs to the test output if `RUST_LOG` is set.
fn init_logging() {
if std::env::var_os("RUST_LOG").is_some() {