From a38215de98b087b64a51bedf6cb03c4fa1dd716d Mon Sep 17 00:00:00 2001 From: mpostma Date: Wed, 6 Oct 2021 14:34:14 +0200 Subject: [PATCH] edit documentation --- meilisearch-lib/src/index/mod.rs | 20 +++++++++++++------- meilisearch-lib/src/index_controller/mod.rs | 17 ++--------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/meilisearch-lib/src/index/mod.rs b/meilisearch-lib/src/index/mod.rs index ec70e6f50..ad98a8d89 100644 --- a/meilisearch-lib/src/index/mod.rs +++ b/meilisearch-lib/src/index/mod.rs @@ -18,14 +18,16 @@ pub use index::Index; #[cfg(test)] pub use test::MockIndex as Index; +/// The index::test module provides means of mocking an index instance. I can be used throughout the +/// code for unit testing, in places where an index would normally be used. #[cfg(test)] pub mod test { use std::any::Any; use std::collections::HashMap; use std::panic::{RefUnwindSafe, UnwindSafe}; + use std::path::Path; use std::path::PathBuf; - use std::sync::Mutex; - use std::{path::Path, sync::Arc}; + use std::sync::{Arc, Mutex}; use serde_json::{Map, Value}; use uuid::Uuid; @@ -71,9 +73,9 @@ pub mod test { None => (), } - // Since we add assertions in drop implementation for Stub, an panic can occur in a - // panic, cause a hard abort of the program. To handle that, we catch the panic, and - // set the stub as invalidated so the assertions are not run during the drop. + // Since we add assertions in the drop implementation for Stub, a panic can occur in a + // panic, causing a hard abort of the program. To handle that, we catch the panic, and + // set the stub as invalidated so the assertions aren't run during the drop. impl<'a, A, R> RefUnwindSafe for StubHolder<'a, A, R> {} struct StubHolder<'a, A, R>(&'a (dyn Fn(A) -> R + Sync + Send)); @@ -169,8 +171,12 @@ pub mod test { match self.store.get_mut(name) { Some(stub) => stub, None => { - // TODO: this can cause nested panics, because stubs are dropped and panic - // themselves in their drops. + // panic here causes the stubs to get dropped, and panic in turn. To prevent + // that, we forget them, and let them be cleaned by the os later. This is not + // optimal, but is still better than nested panicks. + let mut stubs = self.store.inner.lock().unwrap(); + let stubs = std::mem::replace(&mut *stubs, HashMap::new()); + std::mem::forget(stubs); panic!("unexpected call to {}", name) } } diff --git a/meilisearch-lib/src/index_controller/mod.rs b/meilisearch-lib/src/index_controller/mod.rs index 0b4fd31fa..7273a80db 100644 --- a/meilisearch-lib/src/index_controller/mod.rs +++ b/meilisearch-lib/src/index_controller/mod.rs @@ -267,7 +267,8 @@ impl IndexControllerBuilder { } } -// Using derivative to derive clone here, to ignore U and I bounds. +// We are using derivative here to derive Clone, because U, I and D do not necessarily implement +// Clone themselves. #[derive(derivative::Derivative)] #[derivative(Clone(bound = ""))] pub struct IndexController { @@ -513,20 +514,6 @@ pub async fn get_arc_ownership_blocking(mut item: Arc) -> T { } } -/// Parses the v1 version of the Asc ranking rules `asc(price)`and returns the field name. -pub fn asc_ranking_rule(text: &str) -> Option<&str> { - text.split_once("asc(") - .and_then(|(_, tail)| tail.rsplit_once(")")) - .map(|(field, _)| field) -} - -/// Parses the v1 version of the Desc ranking rules `desc(price)`and returns the field name. -pub fn desc_ranking_rule(text: &str) -> Option<&str> { - text.split_once("desc(") - .and_then(|(_, tail)| tail.rsplit_once(")")) - .map(|(field, _)| field) -} - #[cfg(test)] mod test { use futures::future::ok;