From 25266356d1ddee0db755cfc0d0a16ec1cff46697 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Tue, 18 May 2021 02:52:13 +0800 Subject: [PATCH] fix tests (#495) --- actix-broker/tests/general.rs | 8 ++++++-- actix/src/context.rs | 9 +++++++-- actix/tests/test_address.rs | 6 +++++- actix/tests/test_arbiter.rs | 15 --------------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/actix-broker/tests/general.rs b/actix-broker/tests/general.rs index dfaf5e6b..bef33272 100644 --- a/actix-broker/tests/general.rs +++ b/actix-broker/tests/general.rs @@ -53,8 +53,12 @@ impl Handler for TestActorTwo { #[test] fn it_all_works() { - System::new().block_on(async { + let sys = System::new(); + + sys.block_on(async { TestActorOne.start(); TestActorTwo.start(); - }) + }); + + sys.run().unwrap(); } diff --git a/actix/src/context.rs b/actix/src/context.rs index 6e04d4a7..0187f797 100644 --- a/actix/src/context.rs +++ b/actix/src/context.rs @@ -100,11 +100,15 @@ where /// } /// # impl Actor for Actor2 { /// # type Context = Context; + /// # + /// # fn started(&mut self, _: &mut Self::Context) { + /// # System::current().stop(); + /// # } /// # } /// /// # fn main() { - /// # let mut sys = System::new(); - /// # System::new().block_on(async { + /// # let sys = System::new(); + /// # sys.block_on(async { /// let ctx1 = Context::::new(); /// let ctx2 = Context::::new(); /// @@ -114,6 +118,7 @@ where /// ctx1.run(actor1); /// ctx2.run(actor2); /// # }); + /// # sys.run().unwrap(); /// # } /// ``` #[inline] diff --git a/actix/tests/test_address.rs b/actix/tests/test_address.rs index 2519afc8..34f1a295 100644 --- a/actix/tests/test_address.rs +++ b/actix/tests/test_address.rs @@ -148,9 +148,13 @@ impl Actor for WeakRecipientRunner { #[test] fn test_weak_recipient() { - System::new().block_on(async move { + let sys = System::new(); + + sys.block_on(async move { WeakRecipientRunner.start(); }); + + sys.run().unwrap(); } #[test] diff --git a/actix/tests/test_arbiter.rs b/actix/tests/test_arbiter.rs index 93b596aa..5101b8df 100644 --- a/actix/tests/test_arbiter.rs +++ b/actix/tests/test_arbiter.rs @@ -3,13 +3,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use tokio::sync::oneshot; -#[derive(Debug)] -struct Panic(); - -impl Message for Panic { - type Result = (); -} - #[derive(Debug)] struct Ping(usize); @@ -33,14 +26,6 @@ impl Handler for MyActor { } } -impl Handler for MyActor { - type Result = (); - - fn handle(&mut self, _: Panic, _: &mut actix::Context) { - panic!("Whoops!"); - } -} - #[test] fn test_start_actor_message() { let count = Arc::new(AtomicUsize::new(0));