From 434828c14efe6153293f1bf15097445f06e73f68 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Mon, 25 May 2026 12:05:28 +0200 Subject: [PATCH] test(xy): auto-start + stop/start lifecycle --- crates/xy/tests/lifecycle.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 crates/xy/tests/lifecycle.rs diff --git a/crates/xy/tests/lifecycle.rs b/crates/xy/tests/lifecycle.rs new file mode 100644 index 0000000..4c1ab9a --- /dev/null +++ b/crates/xy/tests/lifecycle.rs @@ -0,0 +1,31 @@ +mod common; +use common::*; + +#[tokio::test] +async fn auto_starts_on_boot_then_stop_and_start() { + let xy = xy_bin(); + let sleeper = sleep_server_bin(); + let mut h = Harness::new(); + h.write_server("alpha", sleeper.to_str().unwrap(), 19_001, "always"); + h.start_daemon(&xy).await; + + let mut last_stdout = String::new(); + for _ in 0..40 { + let (_c, out, _e) = h.run_cli(&xy, &["list"]).await; + last_stdout = out; + if last_stdout.contains("alpha") && last_stdout.contains("running") { + break; + } + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + } + assert!(last_stdout.contains("alpha"), "stdout: {last_stdout}"); + assert!(last_stdout.contains("running"), "stdout: {last_stdout}"); + + let (code, out, _e) = h.run_cli(&xy, &["stop", "alpha"]).await; + assert_eq!(code, 0); + assert!(out.contains("stopped: alpha"), "stdout: {out}"); + + let (code, out, _e) = h.run_cli(&xy, &["start", "alpha"]).await; + assert_eq!(code, 0); + assert!(out.contains("started: alpha"), "stdout: {out}"); +}