remove need for macros feature when testing spawn

This commit is contained in:
Rob Ede 2021-09-01 21:38:05 +01:00
parent 6fae297bbf
commit 6cfa808094
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
2 changed files with 22 additions and 19 deletions

View File

@ -46,7 +46,10 @@ use tokio::task::JoinHandle;
// Cannot define a main macro when compiled into test harness. // Cannot define a main macro when compiled into test harness.
// Workaround for https://github.com/rust-lang/rust/issues/62127. // Workaround for https://github.com/rust-lang/rust/issues/62127.
#[cfg(all(feature = "macros", not(test)))] #[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 arbiter;
mod runtime; mod runtime;

View File

@ -9,7 +9,7 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use actix_rt::{Arbiter, System}; use actix_rt::{task::JoinError, Arbiter, System};
use tokio::sync::oneshot; use tokio::sync::oneshot;
#[test] #[test]
@ -301,25 +301,25 @@ fn try_current_with_system() {
} }
#[allow(clippy::unit_cmp)] #[allow(clippy::unit_cmp)]
#[actix_rt::test] #[test]
async fn spawn_local() { fn spawn_local() {
// demonstrate that spawn -> R is strictly more capable than spawn -> () 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 {}).await.unwrap(), ());
assert_eq!(actix_rt::spawn(async { 1 }).await.unwrap(), 1); assert_eq!(actix_rt::spawn(async { 1 }).await.unwrap(), 1);
assert!(actix_rt::spawn(async { panic!("") }).await.is_err()); assert!(actix_rt::spawn(async { panic!("") }).await.is_err());
actix_rt::spawn(async { tokio::time::sleep(Duration::from_millis(50)).await }) actix_rt::spawn(async { tokio::time::sleep(Duration::from_millis(50)).await })
.await .await
.unwrap(); .unwrap();
use actix_rt::task::JoinError; fn g<F: Future<Output = Result<(), JoinError>>>(_f: F) {}
g(actix_rt::spawn(async {}));
// g(actix_rt::spawn(async { 1 })); // compile err
fn g<F: Future<Output = Result<(), JoinError>>>(_f: F) {} fn h<F: Future<Output = Result<R, JoinError>>, R>(_f: F) {}
g(actix_rt::spawn(async {})); h(actix_rt::spawn(async {}));
// g(actix_rt::spawn(async { 1 })); // compile err h(actix_rt::spawn(async { 1 }));
})
fn h<F: Future<Output = Result<R, JoinError>>, R>(_f: F) {}
h(actix_rt::spawn(async {}));
h(actix_rt::spawn(async { 1 }));
} }