mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-11 05:54:30 +01:00
fix tests
This commit is contained in:
parent
ee675eadf1
commit
c78f351300
@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
use std::sync::Arc;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@ -70,6 +72,70 @@ pub enum IndexError {
|
|||||||
ExistingPrimaryKey,
|
ExistingPrimaryKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl IndexActorHandle for Arc<MockIndexActorHandle> {
|
||||||
|
async fn create_index(&self, uuid: Uuid, primary_key: Option<String>) -> Result<IndexMeta> {
|
||||||
|
self.as_ref().create_index(uuid, primary_key).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update(
|
||||||
|
&self,
|
||||||
|
uuid: Uuid,
|
||||||
|
meta: Processing<UpdateMeta>,
|
||||||
|
data: std::fs::File,
|
||||||
|
) -> anyhow::Result<UpdateResult> {
|
||||||
|
self.as_ref().update(uuid, meta, data).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn search(&self, uuid: Uuid, query: SearchQuery) -> Result<SearchResult> {
|
||||||
|
self.as_ref().search(uuid, query).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn settings(&self, uuid: Uuid) -> Result<Settings> {
|
||||||
|
self.as_ref().settings(uuid).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn documents(
|
||||||
|
&self,
|
||||||
|
uuid: Uuid,
|
||||||
|
offset: usize,
|
||||||
|
limit: usize,
|
||||||
|
attributes_to_retrieve: Option<Vec<String>>,
|
||||||
|
) -> Result<Vec<Document>> {
|
||||||
|
self.as_ref().documents(uuid, offset, limit, attributes_to_retrieve).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn document(
|
||||||
|
&self,
|
||||||
|
uuid: Uuid,
|
||||||
|
doc_id: String,
|
||||||
|
attributes_to_retrieve: Option<Vec<String>>,
|
||||||
|
) -> Result<Document> {
|
||||||
|
self.as_ref().document(uuid, doc_id, attributes_to_retrieve).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete(&self, uuid: Uuid) -> Result<()> {
|
||||||
|
self.as_ref().delete(uuid).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_index_meta(&self, uuid: Uuid) -> Result<IndexMeta> {
|
||||||
|
self.as_ref().get_index_meta(uuid).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_index(&self, uuid: Uuid, index_settings: IndexSettings) -> Result<IndexMeta> {
|
||||||
|
self.as_ref().update_index(uuid, index_settings).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn snapshot(&self, uuid: Uuid, path: PathBuf) -> Result<()> {
|
||||||
|
self.as_ref().snapshot(uuid, path).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_index_stats(&self, uuid: Uuid) -> Result<IndexStats> {
|
||||||
|
self.as_ref().get_index_stats(uuid).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
#[cfg_attr(test, automock)]
|
#[cfg_attr(test, automock)]
|
||||||
pub trait IndexActorHandle {
|
pub trait IndexActorHandle {
|
||||||
|
@ -68,6 +68,7 @@ pub struct IndexSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct IndexStats {
|
pub struct IndexStats {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
@ -83,6 +84,7 @@ pub struct IndexController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Stats {
|
pub struct Stats {
|
||||||
pub database_size: u64,
|
pub database_size: u64,
|
||||||
pub last_update: Option<DateTime<Utc>>,
|
pub last_update: Option<DateTime<Utc>>,
|
||||||
|
@ -71,11 +71,9 @@ where
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.update_handle
|
self.update_handle
|
||||||
.snapshot(uuids, temp_snapshot_path.clone())
|
.snapshot(uuids, temp_snapshot_path.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let snapshot_dir = self.snapshot_path.clone();
|
let snapshot_dir = self.snapshot_path.clone();
|
||||||
let snapshot_path = self
|
let snapshot_path = self
|
||||||
.snapshot_path
|
.snapshot_path
|
||||||
@ -133,19 +131,22 @@ pub fn load_snapshot(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::future::{err, ok};
|
use futures::future::{err, ok};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::index_controller::update_actor::{MockUpdateActorHandle, UpdateError};
|
use crate::index_controller::update_actor::{UpdateError, MockUpdateActorHandle, UpdateActorHandleImpl};
|
||||||
|
use crate::index_controller::index_actor::MockIndexActorHandle;
|
||||||
use crate::index_controller::uuid_resolver::{MockUuidResolverHandle, UuidError};
|
use crate::index_controller::uuid_resolver::{MockUuidResolverHandle, UuidError};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_normal() {
|
async fn test_normal() {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let uuids_num = rng.gen_range(5, 10);
|
let uuids_num: usize = rng.gen_range(5, 10);
|
||||||
let uuids = (0..uuids_num).map(|_| Uuid::new_v4()).collect::<Vec<_>>();
|
let uuids = (0..uuids_num).map(|_| Uuid::new_v4()).collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut uuid_resolver = MockUuidResolverHandle::new();
|
let mut uuid_resolver = MockUuidResolverHandle::new();
|
||||||
@ -155,13 +156,19 @@ mod test {
|
|||||||
.times(1)
|
.times(1)
|
||||||
.returning(move |_| Box::pin(ok(uuids_clone.clone())));
|
.returning(move |_| Box::pin(ok(uuids_clone.clone())));
|
||||||
|
|
||||||
let mut update_handle = MockUpdateActorHandle::new();
|
|
||||||
let uuids_clone = uuids.clone();
|
let uuids_clone = uuids.clone();
|
||||||
update_handle
|
let mut index_handle = MockIndexActorHandle::new();
|
||||||
|
index_handle
|
||||||
.expect_snapshot()
|
.expect_snapshot()
|
||||||
.withf(move |uuid, _path| uuids_clone.contains(uuid))
|
.withf(move |uuid, _path| uuids_clone.contains(uuid))
|
||||||
.times(uuids_num)
|
.times(uuids_num)
|
||||||
.returning(move |_, _| Box::pin(ok(())));
|
.returning(move |_, _| {
|
||||||
|
Box::pin(ok(()))
|
||||||
|
});
|
||||||
|
|
||||||
|
let dir = tempfile::tempdir_in(".").unwrap();
|
||||||
|
let handle = Arc::new(index_handle);
|
||||||
|
let update_handle = UpdateActorHandleImpl::<Vec<u8>>::new(handle.clone(), dir.path(), 4096 * 100).unwrap();
|
||||||
|
|
||||||
let snapshot_path = tempfile::tempdir_in(".").unwrap();
|
let snapshot_path = tempfile::tempdir_in(".").unwrap();
|
||||||
let snapshot_service = SnapshotService::new(
|
let snapshot_service = SnapshotService::new(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user