mirror of https://github.com/fafhrd91/actix-net
remove need for macros feature when testing spawn
This commit is contained in:
parent
6fae297bbf
commit
6cfa808094
|
@ -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;
|
||||||
|
|
|
@ -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 }));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue