arbiter: add tests for Builder API and stop_system_on_panic
@@ -8,6 +8,9 @@ use futures::Future;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
+#[derive(Debug, Message)]
+struct Panic();
+
#[derive(Debug, Message)]
struct Ping(usize);
@@ -27,6 +30,14 @@ impl Handler<Ping> for MyActor {
}
}
+impl Handler<Panic> for MyActor {
+ type Result = ();
+
+ fn handle(&mut self, _: Panic, _: &mut actix::Context<MyActor>) {
+ panic!("Whoops!");
+ }
+}
+
#[test]
fn test_start_actor() {
let count = Arc::new(AtomicUsize::new(0));
@@ -41,6 +52,36 @@ fn test_start_actor() {
assert_eq!(count.load(Ordering::Relaxed), 1);
}
+#[test]
+fn test_start_actor_builder() {
+ let count = Arc::new(AtomicUsize::new(0));
+ let act_count = Arc::clone(&count);
+
+ System::run(move || {
+ let addr = Arbiter::builder().start(move |_| MyActor(act_count));
+
+ addr.do_send(Ping(1));
+ });
+
+ assert_eq!(count.load(Ordering::Relaxed), 1);
+}
+
+#[test]
+fn test_panic_stops_system() {
+ let count = Arc::new(AtomicUsize::new(0));
+ let act_count = Arc::clone(&count);
+
+ let return_code = System::run(move || {
+ let addr = Arbiter::builder()
+ .stop_system_on_panic(true)
+ .start(move |_| MyActor(act_count));
+
+ addr.do_send(Panic());
+ });
+
+ assert_eq!(return_code, 1);
+}
+
#[test]
fn test_start_actor_message() {
let count = Arc::new(AtomicUsize::new(0));
