From 6cfa808094777cf03289d0aee1af5a77e17a9495 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 1 Sep 2021 21:38:05 +0100 Subject: [PATCH] remove need for macros feature when testing spawn --- actix-rt/src/lib.rs | 5 ++++- actix-rt/tests/tests.rs | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index c45251b6..95afcac9 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -46,7 +46,10 @@ use tokio::task::JoinHandle; // Cannot define a main macro when compiled into test harness. // Workaround for https://github.com/rust-lang/rust/issues/62127. #[cfg(all(feature = "macros", not(test)))] -pub use actix_macros::{main, test}; +pub use actix_macros::main; + +#[cfg(feature = "macros")] +pub use actix_macros::test; mod arbiter; mod runtime; diff --git a/actix-rt/tests/tests.rs b/actix-rt/tests/tests.rs index e2c4b262..e66696bf 100644 --- a/actix-rt/tests/tests.rs +++ b/actix-rt/tests/tests.rs @@ -9,7 +9,7 @@ use std::{ time::{Duration, Instant}, }; -use actix_rt::{Arbiter, System}; +use actix_rt::{task::JoinError, Arbiter, System}; use tokio::sync::oneshot; #[test] @@ -301,25 +301,25 @@ fn try_current_with_system() { } #[allow(clippy::unit_cmp)] -#[actix_rt::test] -async fn spawn_local() { - // demonstrate that spawn -> R is strictly more capable than spawn -> () +#[test] +fn spawn_local() { + System::new().block_on(async { + // demonstrate that spawn -> R is strictly more capable than spawn -> () - assert_eq!(actix_rt::spawn(async {}).await.unwrap(), ()); - assert_eq!(actix_rt::spawn(async { 1 }).await.unwrap(), 1); - assert!(actix_rt::spawn(async { panic!("") }).await.is_err()); + assert_eq!(actix_rt::spawn(async {}).await.unwrap(), ()); + assert_eq!(actix_rt::spawn(async { 1 }).await.unwrap(), 1); + assert!(actix_rt::spawn(async { panic!("") }).await.is_err()); - actix_rt::spawn(async { tokio::time::sleep(Duration::from_millis(50)).await }) - .await - .unwrap(); + actix_rt::spawn(async { tokio::time::sleep(Duration::from_millis(50)).await }) + .await + .unwrap(); - use actix_rt::task::JoinError; + fn g>>(_f: F) {} + g(actix_rt::spawn(async {})); + // g(actix_rt::spawn(async { 1 })); // compile err - fn g>>(_f: F) {} - g(actix_rt::spawn(async {})); - // g(actix_rt::spawn(async { 1 })); // compile err - - fn h>, R>(_f: F) {} - h(actix_rt::spawn(async {})); - h(actix_rt::spawn(async { 1 })); + fn h>, R>(_f: F) {} + h(actix_rt::spawn(async {})); + h(actix_rt::spawn(async { 1 })); + }) }