From c1647049a1f7f100c0f2fe6fb96a88a0b01cb6ea Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 4 May 2021 00:35:35 +0100 Subject: [PATCH] apitest: Test save/load, at least a bit Signed-off-by: Ian Jackson --- apitest/apitest.rs | 11 ++++++++++- apitest/at-otter.rs | 17 +++++++++++++++++ src/prelude.rs | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 75b60de0..a71c24c0 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -70,7 +70,7 @@ pub struct Opts { pub struct SetupCore { pub ds: DirSubst, pub mgmt_conn: RefCell, - server_child: Child, + pub server_child: Child, pub wanted_tests: TrackWantedTests, pub cln: cleanup_notify::Handle, } @@ -667,6 +667,15 @@ fn start_gameserver(cln: &cleanup_notify::Handle, ds: &DirSubst) (mgmt_conn, child) } +impl SetupCore { + #[throws(AE)] + pub fn restart_gameserver(&mut self) { + let (mgmt_conn, child) = start_gameserver(&self.cln, &self.ds)?; + self.mgmt_conn = RefCell::new(mgmt_conn); + self.server_child = child; + } +} + // ---------- game spec ---------- #[derive(Copy,Clone,Error,Debug)] diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index f1267471..fd4ff250 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -711,6 +711,22 @@ impl Ctx { let st = Command::new("cmp").args(&[&bundle_file, "00000.zip"]).status()?; if ! st.success() { panic!("cmp failed {}", st) } } + + #[throws(Explode)] + fn save_load(&mut self) { + { + let mut su = self.su_rc.borrow_mut(); + let old_pid = su.server_child.id() as nix::libc::pid_t; + nix::sys::signal::kill(nix::unistd::Pid::from_raw(old_pid), + nix::sys::signal::SIGTERM)?; + let st = dbgc!(su.server_child.wait()?); + assert_eq!(st.signal(), Some(nix::sys::signal::SIGTERM as i32)); + su.restart_gameserver()?; + } + let alice = self.connect_player(&self.alice)?; + let pieces = alice.pieces::()?; + dbgc!(pieces); + } } #[throws(Explode)] @@ -720,6 +736,7 @@ fn tests(mut c: Ctx) { test!(c, "specs", c.chdir_root(|c| c.specs() )); test!(c, "put-back", c.put_back() ?); test!(c, "bundles", c.bundles() ?); + test!(c, "save-load", c.save_load() ?); } #[throws(Explode)] diff --git a/src/prelude.rs b/src/prelude.rs index dce8bf08..1f45a801 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -38,7 +38,7 @@ pub use std::os::unix; pub use std::os::unix::ffi::OsStrExt; pub use std::os::unix::io::IntoRawFd; pub use std::os::unix::net::UnixStream; -pub use std::os::unix::process::CommandExt; +pub use std::os::unix::process::{CommandExt, ExitStatusExt}; pub use std::path::PathBuf; pub use std::process::{exit, Child, Command, Stdio}; pub use std::str; -- 2.30.2