atomr_testkit/
test_kit.rs1use std::time::Duration;
5
6use atomr_config::Config;
7use atomr_core::actor::ActorSystem;
8
9use crate::probe::TestProbe;
10
11pub struct TestKit {
12 pub system: ActorSystem,
13 pub default_timeout: Duration,
14}
15
16impl TestKit {
17 pub async fn new(name: &str) -> Self {
18 let system = ActorSystem::create(name, Config::reference()).await.expect("create system");
19 Self { system, default_timeout: Duration::from_secs(3) }
20 }
21
22 pub fn probe<M: Send + 'static>(&self, name: &str) -> TestProbe<M> {
23 TestProbe::new(name)
24 }
25
26 pub async fn shutdown(self) {
27 self.system.terminate().await;
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[tokio::test]
36 async fn kit_boots_and_shuts_down() {
37 let kit = TestKit::new("kit").await;
38 assert_eq!(kit.system.name(), "kit");
39 kit.shutdown().await;
40 }
41}