diff --git a/test-utils/actix-test-utils/src/lib.rs b/test-utils/actix-test-utils/src/lib.rs index 051c3174160..5ad286871af 100644 --- a/test-utils/actix-test-utils/src/lib.rs +++ b/test-utils/actix-test-utils/src/lib.rs @@ -1,10 +1,5 @@ -use actix_rt::signal; -use futures::{future, select, task::Poll, FutureExt}; use once_cell::sync::Lazy; -use std::sync::{ - atomic::{AtomicBool, Ordering}, - Mutex, -}; +use std::sync::Mutex; pub struct ShutdownableThread { pub join: Option>, @@ -40,32 +35,11 @@ impl Drop for ShutdownableThread { } } -static CAUGHT_SIGINT: AtomicBool = AtomicBool::new(false); - -macro_rules! handle_interrupt { - ($future:expr) => { - async move { - assert!(!CAUGHT_SIGINT.load(Ordering::SeqCst), "SIGINT received"); - select! { - _ = { - future::poll_fn(|_| { - if CAUGHT_SIGINT.load(Ordering::SeqCst) { - return Poll::Ready(()); - } - Poll::Pending - }) - }.fuse() => panic!("SIGINT received"), - output = $future.fuse() => output, - } - } - }; -} - #[inline] pub fn spawn_interruptible( f: F, ) -> actix_rt::task::JoinHandle { - actix_rt::spawn(handle_interrupt!(f)) + actix_rt::spawn(f) } // Number of actix instances that are currently running. @@ -80,30 +54,12 @@ pub fn setup_actix() -> actix_rt::SystemRunner { let default_hook = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { if actix_rt::System::is_registered() { - let exit_code = if CAUGHT_SIGINT.load(Ordering::SeqCst) { 130 } else { 1 }; - actix_rt::System::current().stop_with_code(exit_code); + actix_rt::System::current().stop_with_code(1); } default_hook(info); })); }); - static TRAP_SIGINT_HOOK: std::sync::Once = std::sync::Once::new(); - - // This is a workaround to ensure all threads get the exit memo. - // Plainly polling ctrl_c() on busy threads like ours can be problematic. - TRAP_SIGINT_HOOK.call_once(|| { - std::thread::Builder::new() - .name("SIGINT trap".into()) - .spawn(|| { - let sys = actix_rt::System::new(); - sys.block_on(async { - signal::ctrl_c().await.expect("failed to listen for SIGINT"); - CAUGHT_SIGINT.store(true, Ordering::SeqCst); - }); - sys.run().unwrap(); - }) - .expect("failed to spawn SIGINT handler thread"); - }); actix_rt::System::new() } @@ -111,7 +67,7 @@ pub fn block_on_interruptible( sys: &actix_rt::SystemRunner, f: F, ) -> F::Output { - sys.block_on(handle_interrupt!(f)) + sys.block_on(f) } pub fn run_actix(f: F) {