From e3b6a33b97d1af2485d0bf84620fc4139ec59494 Mon Sep 17 00:00:00 2001 From: Jonathas-Conceicao Date: Wed, 5 Feb 2020 22:59:45 -0300 Subject: [PATCH] Add integration tests These initial tests validade basic usage with timed futures for: - `System::block_on`; - `Arbiter::new`; - `Arbiter::stop`; - `Arbiter::join`; Signed-off-by: Jonathas-Conceicao --- actix-rt/tests/wait_spawned.rs | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 actix-rt/tests/wait_spawned.rs diff --git a/actix-rt/tests/wait_spawned.rs b/actix-rt/tests/wait_spawned.rs new file mode 100644 index 00000000..e3296e89 --- /dev/null +++ b/actix-rt/tests/wait_spawned.rs @@ -0,0 +1,63 @@ +use std::time::{Duration, Instant}; + +#[test] +fn await_for_timer() { + let time = Duration::from_secs(2); + let instant = Instant::now(); + actix_rt::System::new("test_wait_timer").block_on(async move { + tokio::time::delay_for(time).await; + }); + assert!( + instant.elapsed() >= time, + "Block on should poll awaited future to completion" + ); +} + +#[test] +fn join_another_arbiter() { + let time = Duration::from_secs(2); + let instant = Instant::now(); + actix_rt::System::new("test_join_another_arbiter").block_on(async move { + let mut arbiter = actix_rt::Arbiter::new(); + arbiter.send(Box::pin(async move { + tokio::time::delay_for(time).await; + actix_rt::Arbiter::current().stop(); + })); + arbiter.join().unwrap(); + }); + assert!( + instant.elapsed() >= time, + "Join on another arbiter should complete only when it calls stop" + ); + + let instant = Instant::now(); + actix_rt::System::new("test_join_another_arbiter").block_on(async move { + let mut arbiter = actix_rt::Arbiter::new(); + arbiter.exec_fn(move || { + actix_rt::spawn(async move { + tokio::time::delay_for(time).await; + actix_rt::Arbiter::current().stop(); + }); + }); + arbiter.join().unwrap(); + }); + assert!( + instant.elapsed() >= time, + "Join on a arbiter that has used actix_rt::spawn should wait for said future" + ); + + let instant = Instant::now(); + actix_rt::System::new("test_join_another_arbiter").block_on(async move { + let mut arbiter = actix_rt::Arbiter::new(); + arbiter.send(Box::pin(async move { + tokio::time::delay_for(time).await; + actix_rt::Arbiter::current().stop(); + })); + arbiter.stop(); + arbiter.join().unwrap(); + }); + assert!( + instant.elapsed() < time, + "Premature stop of arbiter should conclude regardless of it's current state" + ); +}