use aktrs::actor::{testkit::ActorTestKit, Behaviors, SpawnOptions}; use std::panic; use std::time::Duration; #[aktrs::test] fn probe_expect_message_ok(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); let _ = probe.pid().try_tell(123); probe.expect_message_within(123, Duration::from_millis(5)); Ok(()) } #[aktrs::test] #[should_panic] fn probe_expect_message_err(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); let _ = probe.pid().try_tell(123); probe.expect_message_within(321, Duration::from_millis(5)); // <- panic Ok(()) } #[aktrs::test] #[should_panic] fn probe_expect_message_timeout(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); probe.expect_message_within(123, Duration::from_millis(5)); // <- panic Ok(()) } #[aktrs::test] fn probe_expect_no_message_ok(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); probe.expect_no_message_for(Duration::from_millis(5)); Ok(()) } #[aktrs::test] #[should_panic] fn probe_expect_no_message_err(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); let _ = probe.pid().try_tell(123); probe.expect_no_message_for(Duration::from_millis(5)); // <- panic Ok(()) } #[aktrs::test] fn probe_receive_message_ok(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); let _ = probe.pid().try_tell(123); assert_eq!(probe.receive_message(), 123); Ok(()) } #[aktrs::test] #[should_panic] fn probe_receive_message_timeout(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe::(); probe.receive_message_within(Duration::from_millis(5)); // <- panic Ok(()) } #[aktrs::test] #[should_panic] #[ignore] // FIXME fn panic_in_actor_system(mut t: ActorTestKit) -> aktrs::Result<()> { panic::set_hook(Box::new(|_| {})); let actor = Behaviors::receive_message(|_, _| panic!()); let mut pid = t.spawn(actor, SpawnOptions::default()); t.block_on(pid.tell(()))?; Ok(()) // <- panic (when actor test kit is dropped) }