chiark / gitweb /
apitest: Test save/load, at least a bit
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 23:35:35 +0000 (00:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 23:35:42 +0000 (00:35 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs
src/prelude.rs

index 75b60de05e7bc4cd187c4ec056c3b99ce9cb8ff7..a71c24c0e37010a4d424ee78d60f55db9e535dfa 100644 (file)
@@ -70,7 +70,7 @@ pub struct Opts {
 pub struct SetupCore {
   pub ds: DirSubst,
   pub mgmt_conn: RefCell<MgmtChannelForGame>,
-  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)]
index f126747151daa362217486968608421cb515f9aa..fd4ff250013dc49bbb4db0e7c26f8289d683c298 100644 (file)
@@ -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::<PIA>()?;
+    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)]
index dce8bf08f3d8debe081183b43d230bd42eca0a51..1f45a80114478f5cc466664c2a9533f5a3c08f1d 100644 (file)
@@ -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;