use aktrs::actor::{testkit::ActorTestKit, Behaviors, Signal, SpawnOptions}; use aktrs::reexport::anyhow::bail; use std::sync::{Arc, Barrier}; use std::time::Duration; #[aktrs::test] fn pid_is_alive(mut t: ActorTestKit) -> aktrs::Result<()> { let mut probe = t.create_anonymous_test_probe(); let mut probe_pid = probe.pid(); let b = Arc::new(Barrier::new(2)); let b2 = Arc::clone(&b); let actor = Behaviors::<()>::with_context(move |cx| { let child = Behaviors::<()>::with_context(move |cx| { cx.timers().start_single_timer(Duration::from_millis(10), || ()); Ok(Behaviors::receive_message(|_, _| bail!("error")).into()) }); let child_pid = cx.spawn(child, SpawnOptions::default()); probe_pid.try_tell(child_pid)?; Ok(Behaviors::receive_signal(move |_, signal| match signal { Signal::ChildFailed(..) => { b2.wait(); Ok(Behaviors::stopped()) } _ => Ok(Behaviors::unhandled()), })) }); t.spawn(actor, SpawnOptions::default()); let child_pid = probe.receive_message(); assert!(child_pid.is_alive()); b.wait(); assert!(!child_pid.is_alive()); Ok(()) }