chiark / gitweb /
apitest: Make MgmtConn a RefCell
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:21:39 +0000 (18:21 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:50:57 +0000 (18:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs
wdriver/wdriver.rs

index 65856dde27c78f1b4431ccac59da82bd214ee059..27c0f87322d1e709813558535a387127a831be2f 100644 (file)
@@ -14,6 +14,8 @@ pub mod imports {
 pub use imports::*;
 pub use otter::prelude::*;
 
+pub use std::cell::{RefCell, RefMut};
+
 pub use num_traits::NumCast;
 pub use serde_json::json;
 pub use structopt::StructOpt;
@@ -67,7 +69,7 @@ pub struct Opts {
 #[derive(Debug)]
 pub struct SetupCore {
   pub ds: DirSubst,
-  pub mgmt_conn: MgmtChannelForGame,
+  pub mgmt_conn: RefCell<MgmtChannelForGame>,
   server_child: Child,
   pub wanted_tests: TrackWantedTests,
 }
@@ -779,6 +781,10 @@ impl SetupCore {
   pub fn pause_otter(&self) -> OtterPaused {
     self.otter_pauseable().pause()?
   }
+
+  pub fn mgmt_conn<'m>(&'m self) -> RefMut<'m, MgmtChannelForGame> {
+    self.mgmt_conn.borrow_mut()
+  }
 }
 
 impl OtterPauseable {
@@ -903,7 +909,7 @@ pub fn setup_core<O>(module_paths: &[&str], early_args: EarlyArgPredicate) ->
    ),
    SetupCore {
      ds,
-     mgmt_conn,
+     mgmt_conn: mgmt_conn.into(),
      server_child,
      wanted_tests,
    })
index 2a7ad118c4a5eeae722e35fc47c8d0fa25dd5321..7acb3b145561a2817d167a5425fb59fa5a163c5e 100644 (file)
@@ -332,8 +332,8 @@ impl Session {
      mut f: F
   ) {
     let exp = {
-      let mut su = self.su_rc.borrow_mut();
-      su.mgmt_conn.game_synch(TABLE.parse().unwrap())?
+      self.su_rc.borrow_mut().mgmt_conn()
+        .game_synch(TABLE.parse().unwrap())?
     };
     let efwrap = ef.map(|ef| {
       move |s: &mut _, g, v: &_| { ef(s,g,v)?; Ok::<_,AE>(None) }
@@ -529,7 +529,7 @@ impl Ctx {
     prepare_game(&self.su().ds, TABLE)?;
     let mut alice = self.connect_player(&self.alice)?;
     let mut bob = self.connect_player(&self.bob)?;
-    self.su_mut().mgmt_conn.fakerng_load(&[&"1",&"0"])?;
+    self.su_mut().mgmt_conn().fakerng_load(&[&"1",&"0"])?;
 
     let mut a_pieces = alice.pieces::<PIA>()?;
     let mut b_pieces = alice.pieces::<PIB>()?;
index 2e54e4e58f8d4894051229e1f7583e6328b7c304..171389f757834176cf0940ae92d08d86bf7abe2f 100644 (file)
@@ -493,7 +493,7 @@ impl<'g> WindowGuard<'g> {
 
   #[throws(AE)]
   fn synch_raw(&mut self) {
-    let gen = self.su.mgmt_conn.game_synch(self.w.instance.clone())?;
+    let gen = self.su.mgmt_conn().game_synch(self.w.instance.clone())?;
     (|| {
       loop {
         info!("{:?} gen={}", self, gen);