diff --git a/quickwit/quickwit-actors/Cargo.toml b/quickwit/quickwit-actors/Cargo.toml index b7b7cb354d8..9b066c4321e 100644 --- a/quickwit/quickwit-actors/Cargo.toml +++ b/quickwit/quickwit-actors/Cargo.toml @@ -18,11 +18,12 @@ futures = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } -quickwit-common = { workspace = true } -quickwit-proto = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +quickwit-common = { workspace = true } +quickwit-proto = { workspace = true } + [features] testsuite = [] diff --git a/quickwit/quickwit-actors/src/lib.rs b/quickwit/quickwit-actors/src/lib.rs index 5b56166220a..c8058f4b4c2 100644 --- a/quickwit/quickwit-actors/src/lib.rs +++ b/quickwit/quickwit-actors/src/lib.rs @@ -46,7 +46,7 @@ mod spawn_builder; mod supervisor; #[cfg(test)] -mod tests; +pub(crate) mod tests; mod universe; pub use actor::{Actor, ActorExitStatus, Handler}; @@ -93,13 +93,3 @@ impl ServiceError for AskError { } } } - -struct TestActor; - -impl Actor for TestActor { - type ObservableState = usize; - - fn observable_state(&self) -> Self::ObservableState { - 0 - } -} diff --git a/quickwit/quickwit-actors/src/mailbox.rs b/quickwit/quickwit-actors/src/mailbox.rs index 45cf11f204e..b421b39bde3 100644 --- a/quickwit/quickwit-actors/src/mailbox.rs +++ b/quickwit/quickwit-actors/src/mailbox.rs @@ -304,18 +304,18 @@ impl WeakMailbox { #[cfg(test)] mod tests { use super::*; - use crate::TestActor; + use crate::tests::PingReceiverActor; #[test] fn test_weak_mailbox_downgrade_upgrade() { - let (mailbox, _inbox) = create_test_mailbox::(); + let (mailbox, _inbox) = create_test_mailbox::(); let weak_mailbox = mailbox.downgrade(); assert!(weak_mailbox.upgrade().is_some()); } #[test] fn test_weak_mailbox_failing_upgrade() { - let (mailbox, _inbox) = create_test_mailbox::(); + let (mailbox, _inbox) = create_test_mailbox::(); let weak_mailbox = mailbox.downgrade(); drop(mailbox); assert!(weak_mailbox.upgrade().is_none()); diff --git a/quickwit/quickwit-actors/src/registry.rs b/quickwit/quickwit-actors/src/registry.rs index 5306da86108..0c35f32abfc 100644 --- a/quickwit/quickwit-actors/src/registry.rs +++ b/quickwit/quickwit-actors/src/registry.rs @@ -124,13 +124,10 @@ impl ActorRegistry { })); } - // As far as I can tell this is a false alarm from clippy. - #[allow(clippy::await_holding_lock)] pub async fn observe(&self, timeout: Duration) -> Vec { self.gc(); - let rlock = self.actors.read().unwrap(); let mut obs_futures = Vec::new(); - for registry_for_type in rlock.values() { + for registry_for_type in self.actors.read().unwrap().values() { for obs in ®istry_for_type.observables { if obs.is_disconnected() { continue; @@ -150,7 +147,6 @@ impl ActorRegistry { }); } } - drop(rlock); future::join_all(obs_futures.into_iter()).await } @@ -193,38 +189,39 @@ fn get_iter( mod tests { use std::time::Duration; - use crate::{TestActor, Universe}; + use crate::tests::PingReceiverActor; + use crate::Universe; #[tokio::test] async fn test_registry() { - let test_actor = TestActor; + let test_actor = PingReceiverActor::default(); let universe = Universe::new(); let (_mailbox, _handle) = universe.spawn_builder().spawn(test_actor); - let _actor_mailbox = universe.get_one::().unwrap(); + let _actor_mailbox = universe.get_one::().unwrap(); } #[tokio::test] async fn test_registry_killed_actor() { - let test_actor = TestActor; + let test_actor = PingReceiverActor::default(); let universe = Universe::new(); let (_mailbox, handle) = universe.spawn_builder().spawn(test_actor); handle.kill().await; - assert!(universe.get_one::().is_none()); + assert!(universe.get_one::().is_none()); } #[tokio::test] async fn test_registry_last_mailbox_dropped_actor() { - let test_actor = TestActor; + let test_actor = PingReceiverActor::default(); let universe = Universe::new(); let (mailbox, handle) = universe.spawn_builder().spawn(test_actor); drop(mailbox); handle.join().await; - assert!(universe.get_one::().is_none()); + assert!(universe.get_one::().is_none()); } #[tokio::test] async fn test_get_actor_states() { - let test_actor = TestActor; + let test_actor = PingReceiverActor::default(); let universe = Universe::new(); let (_mailbox, _handle) = universe.spawn_builder().spawn(test_actor); let obs = universe.observe(Duration::from_millis(1000)).await;