mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-26 19:47:43 +02:00
remove RUNNING Q PENDING thread locals from actix-rt (#207)
This commit is contained in:
@ -1,19 +1,5 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[test]
|
||||
fn start_and_stop() {
|
||||
actix_rt::System::new("start_and_stop").block_on(async move {
|
||||
assert!(
|
||||
actix_rt::Arbiter::is_running(),
|
||||
"System doesn't seem to have started"
|
||||
);
|
||||
});
|
||||
assert!(
|
||||
!actix_rt::Arbiter::is_running(),
|
||||
"System doesn't seem to have stopped"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn await_for_timer() {
|
||||
let time = Duration::from_secs(2);
|
||||
@ -76,39 +62,65 @@ fn join_another_arbiter() {
|
||||
);
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn join_current_arbiter() {
|
||||
// let time = Duration::from_secs(2);
|
||||
//
|
||||
// let instant = Instant::now();
|
||||
// actix_rt::System::new("test_join_current_arbiter").block_on(async move {
|
||||
// actix_rt::spawn(async move {
|
||||
// tokio::time::delay_for(time).await;
|
||||
// actix_rt::Arbiter::current().stop();
|
||||
// });
|
||||
// actix_rt::Arbiter::local_join().await;
|
||||
// });
|
||||
// assert!(
|
||||
// instant.elapsed() >= time,
|
||||
// "Join on current arbiter should wait for all spawned futures"
|
||||
// );
|
||||
//
|
||||
// let large_timer = Duration::from_secs(20);
|
||||
// let instant = Instant::now();
|
||||
// actix_rt::System::new("test_join_current_arbiter").block_on(async move {
|
||||
// actix_rt::spawn(async move {
|
||||
// tokio::time::delay_for(time).await;
|
||||
// actix_rt::Arbiter::current().stop();
|
||||
// });
|
||||
// let f = actix_rt::Arbiter::local_join();
|
||||
// actix_rt::spawn(async move {
|
||||
// tokio::time::delay_for(large_timer).await;
|
||||
// actix_rt::Arbiter::current().stop();
|
||||
// });
|
||||
// f.await;
|
||||
// });
|
||||
// assert!(
|
||||
// instant.elapsed() < large_timer,
|
||||
// "local_join should await only for the already spawned futures"
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn join_current_arbiter() {
|
||||
let time = Duration::from_secs(2);
|
||||
fn non_static_block_on() {
|
||||
let string = String::from("test_str");
|
||||
let str = string.as_str();
|
||||
|
||||
let instant = Instant::now();
|
||||
actix_rt::System::new("test_join_current_arbiter").block_on(async move {
|
||||
actix_rt::spawn(async move {
|
||||
tokio::time::delay_for(time).await;
|
||||
actix_rt::Arbiter::current().stop();
|
||||
});
|
||||
actix_rt::Arbiter::local_join().await;
|
||||
});
|
||||
assert!(
|
||||
instant.elapsed() >= time,
|
||||
"Join on current arbiter should wait for all spawned futures"
|
||||
);
|
||||
let mut sys = actix_rt::System::new("borrow some");
|
||||
|
||||
let large_timer = Duration::from_secs(20);
|
||||
let instant = Instant::now();
|
||||
actix_rt::System::new("test_join_current_arbiter").block_on(async move {
|
||||
actix_rt::spawn(async move {
|
||||
tokio::time::delay_for(time).await;
|
||||
actix_rt::Arbiter::current().stop();
|
||||
});
|
||||
let f = actix_rt::Arbiter::local_join();
|
||||
actix_rt::spawn(async move {
|
||||
tokio::time::delay_for(large_timer).await;
|
||||
actix_rt::Arbiter::current().stop();
|
||||
});
|
||||
f.await;
|
||||
sys.block_on(async {
|
||||
actix_rt::time::delay_for(Duration::from_millis(1)).await;
|
||||
assert_eq!("test_str", str);
|
||||
});
|
||||
assert!(
|
||||
instant.elapsed() < large_timer,
|
||||
"local_join should await only for the already spawned futures"
|
||||
);
|
||||
|
||||
let mut rt = actix_rt::Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
actix_rt::time::delay_for(Duration::from_millis(1)).await;
|
||||
assert_eq!("test_str", str);
|
||||
});
|
||||
|
||||
actix_rt::System::run(|| {
|
||||
assert_eq!("test_str", str);
|
||||
actix_rt::System::current().stop();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user