From 110dc01f4004a9f2c935dd133a8bc3d73465b990 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 11:00:56 +0200 Subject: [PATCH 01/15] only check the consistency of the index-scheduler on snapshots when running in release mode --- index-scheduler/src/insta_snapshot.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index-scheduler/src/insta_snapshot.rs b/index-scheduler/src/insta_snapshot.rs index c65bb0716..f295e35b6 100644 --- a/index-scheduler/src/insta_snapshot.rs +++ b/index-scheduler/src/insta_snapshot.rs @@ -11,6 +11,9 @@ use crate::index_mapper::IndexMapper; use crate::{IndexScheduler, Kind, Status, BEI128}; pub fn snapshot_index_scheduler(scheduler: &IndexScheduler) -> String { + // Since we'll snapshot the index right afterward, we don't need to ensure it's internally consistent for every run. + // We can only do it for the release run, where the function runs way faster. + #[cfg(not(debug_assertions))] scheduler.assert_internally_consistent(); let IndexScheduler { From 2d9a055fb90747bef2c40e33314504eac5dad54e Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 12:04:09 +0200 Subject: [PATCH 02/15] stops snapshotting in advance_till when we don't need to --- index-scheduler/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index c9ea70bb8..f91cf955a 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -2000,11 +2000,13 @@ mod tests { fn advance_till(&mut self, breakpoints: impl IntoIterator) { for breakpoint in breakpoints { let b = self.advance(); - let state = snapshot_index_scheduler(&self.index_scheduler); assert_eq!( - b, breakpoint, - "Was expecting the breakpoint `{:?}` but instead got `{:?}`.\n{state}", - breakpoint, b + b, + breakpoint, + "Was expecting the breakpoint `{:?}` but instead got `{:?}`.\n{}", + breakpoint, + b, + snapshot_index_scheduler(&self.index_scheduler) ); } } @@ -2028,7 +2030,6 @@ mod tests { // Wait for one successful batch. #[track_caller] fn advance_one_successful_batch(&mut self) { - self.index_scheduler.assert_internally_consistent(); self.advance_till([Start, BatchCreated]); loop { match self.advance() { @@ -2047,7 +2048,6 @@ mod tests { } self.advance_till([AfterProcessing]); - self.index_scheduler.assert_internally_consistent(); } // Wait for one failed batch. From e5345fb0ebcb2c970b201cd78b8c00375e783b80 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 16:32:50 +0200 Subject: [PATCH 03/15] shave off 15s by providing a shared instance to the integration tests --- meilisearch/tests/common/mod.rs | 1 + meilisearch/tests/common/server.rs | 29 ++ meilisearch/tests/documents/add_documents.rs | 16 +- meilisearch/tests/documents/errors.rs | 107 +++---- .../1.snap | 2 +- .../2.snap | 2 +- meilisearch/tests/index/errors.rs | 30 +- meilisearch/tests/logs/error.rs | 8 +- meilisearch/tests/search/errors.rs | 279 +++++++++--------- .../distinct_at_search_time/succeed.snap | 2 +- meilisearch/tests/settings/errors.rs | 24 +- meilisearch/tests/swap_indexes/errors.rs | 4 +- meilisearch/tests/tasks/errors.rs | 26 +- meilisearch/tests/tasks/mod.rs | 8 +- meilisearch/tests/vector/mod.rs | 24 +- meilisearch/tests/vector/rest.rs | 24 +- meilisearch/tests/vector/settings.rs | 2 +- .../document-added.snap | 2 +- .../document-deleted.snap | 2 +- .../settings-processed.snap | 2 +- 20 files changed, 297 insertions(+), 297 deletions(-) diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index ee1d8aa6e..0c4e8e25c 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -81,6 +81,7 @@ impl Display for Value { f, "{}", json_string!(self, { + ".uid" => "[uid]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index d5c6c20f9..ffa455892 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -16,6 +16,7 @@ use tempfile::TempDir; use tokio::time::sleep; use tracing::level_filters::LevelFilter; use tracing_subscriber::Layer; +use uuid::Uuid; use super::index::Index; use super::service::Service; @@ -30,8 +31,30 @@ pub struct Server { } pub static TEST_TEMP_DIR: Lazy = Lazy::new(|| TempDir::new().unwrap()); +pub static TEST_SHARED_INSTANCE: Lazy = Lazy::new(Server::init_new_shared_instance); impl Server { + fn init_new_shared_instance() -> Self { + let dir = TempDir::new().unwrap(); + + if cfg!(windows) { + std::env::set_var("TMP", TEST_TEMP_DIR.path()); + } else { + std::env::set_var("TMPDIR", TEST_TEMP_DIR.path()); + } + + let options = default_settings(dir.path()); + + let (index_scheduler, auth) = setup_meilisearch(&options).unwrap(); + let service = Service { index_scheduler, auth, options, api_key: None }; + + Server { service, _dir: Some(dir) } + } + + pub async fn new_shared() -> &'static Self { + &TEST_SHARED_INSTANCE + } + pub async fn new() -> Self { let dir = TempDir::new().unwrap(); @@ -108,6 +131,12 @@ impl Server { .await } + /// Returns a view to an index. There is no guarantee that the index exists. + pub fn unique_index(&self) -> Index<'_> { + let uuid = Uuid::new_v4(); + self.index_with_encoder(uuid.to_string(), Encoder::Plain) + } + /// Returns a view to an index. There is no guarantee that the index exists. pub fn index(&self, uid: impl AsRef) -> Index<'_> { self.index_with_encoder(uid, Encoder::Plain) diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index 7c5f3efd3..819b2ddc2 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -1110,7 +1110,7 @@ async fn document_addition_with_huge_int_primary_key() { snapshot!(response, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1402,7 +1402,7 @@ async fn error_document_field_limit_reached_over_multiple_documents() { snapshot!(response, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1436,7 +1436,7 @@ async fn error_document_field_limit_reached_over_multiple_documents() { snapshot!(response, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "test", "status": "failed", "type": "documentAdditionOrUpdate", @@ -1485,7 +1485,7 @@ async fn error_document_field_limit_reached_in_one_nested_document() { snapshot!(response, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1528,7 +1528,7 @@ async fn error_document_field_limit_reached_over_multiple_documents_with_nested_ snapshot!(response, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1563,7 +1563,7 @@ async fn error_document_field_limit_reached_over_multiple_documents_with_nested_ snapshot!(response, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -2209,7 +2209,7 @@ async fn add_invalid_geo_and_then_settings() { let ret = index.wait_task(ret.uid()).await; snapshot!(ret, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -2231,7 +2231,7 @@ async fn add_invalid_geo_and_then_settings() { let ret = index.wait_task(ret.uid()).await; snapshot!(ret, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "test", "status": "failed", "type": "settingsUpdate", diff --git a/meilisearch/tests/documents/errors.rs b/meilisearch/tests/documents/errors.rs index 8db761cb8..600b3b272 100644 --- a/meilisearch/tests/documents/errors.rs +++ b/meilisearch/tests/documents/errors.rs @@ -6,7 +6,7 @@ use crate::json; #[actix_rt::test] async fn get_all_documents_bad_offset() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.get_all_documents_raw("?offset").await; @@ -45,7 +45,7 @@ async fn get_all_documents_bad_offset() { #[actix_rt::test] async fn get_all_documents_bad_limit() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.get_all_documents_raw("?limit").await; @@ -84,7 +84,7 @@ async fn get_all_documents_bad_limit() { #[actix_rt::test] async fn get_all_documents_bad_filter() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); // Since the filter can't be parsed automatically by deserr, we have the wrong error message @@ -123,35 +123,8 @@ async fn get_all_documents_bad_filter() { } "###); - let (response, code) = index.create(None).await; - snapshot!(code, @"202 Accepted"); - snapshot!(json_string!(response, { ".enqueuedAt" => "[date]" }), @r###" - { - "taskUid": 0, - "indexUid": "test", - "status": "enqueued", - "type": "indexCreation", - "enqueuedAt": "[date]" - } - "###); - let response = server.wait_task(0).await; - snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" - { - "uid": 0, - "indexUid": "test", - "status": "succeeded", - "type": "indexCreation", - "canceledBy": null, - "details": { - "primaryKey": null - }, - "error": null, - "duration": "[duration]", - "enqueuedAt": "[date]", - "startedAt": "[date]", - "finishedAt": "[date]" - } - "###); + let (response, _code) = index.create(None).await; + server.wait_task(response.uid()).await.succeeded(); let (response, code) = index.get_all_documents_raw("?filter").await; snapshot!(code, @"200 OK"); @@ -189,7 +162,7 @@ async fn get_all_documents_bad_filter() { #[actix_rt::test] async fn delete_documents_batch() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.delete_batch_raw(json!("doggo")).await; @@ -206,7 +179,7 @@ async fn delete_documents_batch() { #[actix_rt::test] async fn replace_documents_missing_payload() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = @@ -248,7 +221,7 @@ async fn replace_documents_missing_payload() { #[actix_rt::test] async fn update_documents_missing_payload() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.raw_update_documents("", Some("application/json"), "").await; @@ -287,7 +260,7 @@ async fn update_documents_missing_payload() { #[actix_rt::test] async fn replace_documents_missing_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.raw_add_documents("", Vec::new(), "").await; @@ -316,7 +289,7 @@ async fn replace_documents_missing_content_type() { #[actix_rt::test] async fn update_documents_missing_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.raw_update_documents("", None, "").await; @@ -345,7 +318,7 @@ async fn update_documents_missing_content_type() { #[actix_rt::test] async fn replace_documents_bad_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.raw_add_documents("", vec![("Content-Type", "doggo")], "").await; @@ -362,7 +335,7 @@ async fn replace_documents_bad_content_type() { #[actix_rt::test] async fn update_documents_bad_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.raw_update_documents("", Some("doggo"), "").await; @@ -379,7 +352,7 @@ async fn update_documents_bad_content_type() { #[actix_rt::test] async fn replace_documents_bad_csv_delimiter() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index @@ -428,7 +401,7 @@ async fn replace_documents_bad_csv_delimiter() { #[actix_rt::test] async fn update_documents_bad_csv_delimiter() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = @@ -475,7 +448,7 @@ async fn update_documents_bad_csv_delimiter() { #[actix_rt::test] async fn replace_documents_csv_delimiter_with_bad_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index @@ -507,7 +480,7 @@ async fn replace_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn update_documents_csv_delimiter_with_bad_content_type() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = @@ -537,13 +510,13 @@ async fn update_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn delete_document_by_filter() { - let server = Server::new().await; - let index = server.index("doggo"); + let server = Server::new_shared().await; + let index = server.index("tests-documents-errors-delete_document_by_filter"); // send a bad payload type let (response, code) = index.delete_document_by_filter(json!("hello")).await; snapshot!(code, @"400 Bad Request"); - snapshot!(json_string!(response), @r###" + snapshot!(response, @r###" { "message": "Invalid value type: expected an object, but found a string: `\"hello\"`", "code": "bad_request", @@ -555,7 +528,7 @@ async fn delete_document_by_filter() { // send bad payload type let (response, code) = index.delete_document_by_filter(json!({ "filter": true })).await; snapshot!(code, @"400 Bad Request"); - snapshot!(json_string!(response), @r###" + snapshot!(response, @r###" { "message": "Invalid syntax for the filter parameter: `expected String, Array, found: true`.", "code": "invalid_document_filter", @@ -567,7 +540,7 @@ async fn delete_document_by_filter() { // send bad filter let (response, code) = index.delete_document_by_filter(json!({ "filter": "hello"})).await; snapshot!(code, @"400 Bad Request"); - snapshot!(json_string!(response), @r###" + snapshot!(response, @r###" { "message": "Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, `IS NULL`, `IS NOT NULL`, `IS EMPTY`, `IS NOT EMPTY`, `CONTAINS`, `NOT CONTAINS`, `_geoRadius`, or `_geoBoundingBox` at `hello`.\n1:6 hello", "code": "invalid_document_filter", @@ -579,7 +552,7 @@ async fn delete_document_by_filter() { // send empty filter let (response, code) = index.delete_document_by_filter(json!({ "filter": ""})).await; snapshot!(code, @"400 Bad Request"); - snapshot!(json_string!(response), @r###" + snapshot!(response, @r###" { "message": "Sending an empty filter is forbidden.", "code": "invalid_document_filter", @@ -591,7 +564,7 @@ async fn delete_document_by_filter() { // do not send any filter let (response, code) = index.delete_document_by_filter(json!({})).await; snapshot!(code, @"400 Bad Request"); - snapshot!(json_string!(response), @r###" + snapshot!(response, @r###" { "message": "Missing field `filter`", "code": "missing_document_filter", @@ -604,11 +577,11 @@ async fn delete_document_by_filter() { let (response, code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese"})).await; snapshot!(code, @"202 Accepted"); - let response = server.wait_task(response["taskUid"].as_u64().unwrap()).await; - snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]"}), @r###" + let response = server.wait_task(response.uid()).await; + snapshot!(response, @r###" { - "uid": 0, - "indexUid": "doggo", + "uid": "[uid]", + "indexUid": "tests-documents-errors-delete_document_by_filter", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -618,7 +591,7 @@ async fn delete_document_by_filter() { "originalFilter": "\"doggo = bernese\"" }, "error": { - "message": "Index `doggo` not found.", + "message": "Index `tests-documents-errors-delete_document_by_filter` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -632,17 +605,17 @@ async fn delete_document_by_filter() { let (response, code) = index.create(None).await; snapshot!(code, @"202 Accepted"); - server.wait_task(response["taskUid"].as_u64().unwrap()).await; + server.wait_task(response.uid()).await.succeeded(); // no filterable are set let (response, code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese"})).await; snapshot!(code, @"202 Accepted"); - let response = server.wait_task(response["taskUid"].as_u64().unwrap()).await; - snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]"}), @r###" + let response = server.wait_task(response.uid()).await; + snapshot!(response, @r###" { - "uid": 2, - "indexUid": "doggo", + "uid": "[uid]", + "indexUid": "tests-documents-errors-delete_document_by_filter", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -666,17 +639,17 @@ async fn delete_document_by_filter() { let (response, code) = index.update_settings_filterable_attributes(json!(["doggo"])).await; snapshot!(code, @"202 Accepted"); - server.wait_task(response["taskUid"].as_u64().unwrap()).await; + server.wait_task(response.uid()).await.succeeded(); // not filterable while there is a filterable attribute let (response, code) = index.delete_document_by_filter(json!({ "filter": "catto = jorts"})).await; snapshot!(code, @"202 Accepted"); - let response = server.wait_task(response["taskUid"].as_u64().unwrap()).await; - snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]"}), @r###" + let response = server.wait_task(response.uid()).await; + snapshot!(response, @r###" { - "uid": 4, - "indexUid": "doggo", + "uid": "[uid]", + "indexUid": "tests-documents-errors-delete_document_by_filter", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -701,7 +674,7 @@ async fn delete_document_by_filter() { #[actix_rt::test] async fn fetch_document_by_filter() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); index.update_settings_filterable_attributes(json!(["color"])).await; index @@ -798,7 +771,7 @@ async fn fetch_document_by_filter() { #[actix_rt::test] async fn retrieve_vectors() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); // GET ALL DOCUMENTS BY QUERY diff --git a/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/1.snap b/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/1.snap index 4b05d417a..2004eb036 100644 --- a/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/1.snap +++ b/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/1.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/dumps/mod.rs --- { - "uid": 0, + "uid": "[uid]", "indexUid": "pets", "status": "succeeded", "type": "settingsUpdate", diff --git a/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/2.snap b/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/2.snap index 43971924b..8405a0461 100644 --- a/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/2.snap +++ b/meilisearch/tests/dumps/snapshots/mod.rs/generate_and_import_dump_containing_vectors/2.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/dumps/mod.rs --- { - "uid": 1, + "uid": "[uid]", "indexUid": "pets", "status": "succeeded", "type": "documentAdditionOrUpdate", diff --git a/meilisearch/tests/index/errors.rs b/meilisearch/tests/index/errors.rs index 01273fc88..88e197323 100644 --- a/meilisearch/tests/index/errors.rs +++ b/meilisearch/tests/index/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn get_indexes_bad_offset() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.list_indexes_raw("?offset=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -21,7 +21,7 @@ async fn get_indexes_bad_offset() { #[actix_rt::test] async fn get_indexes_bad_limit() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.list_indexes_raw("?limit=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -37,7 +37,7 @@ async fn get_indexes_bad_limit() { #[actix_rt::test] async fn get_indexes_unknown_field() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.list_indexes_raw("?doggo=nolimit").await; snapshot!(code, @"400 Bad Request"); @@ -53,7 +53,7 @@ async fn get_indexes_unknown_field() { #[actix_rt::test] async fn create_index_missing_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.create_index(json!({ "primaryKey": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -69,7 +69,7 @@ async fn create_index_missing_uid() { #[actix_rt::test] async fn create_index_bad_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.create_index(json!({ "uid": "the best doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -96,7 +96,7 @@ async fn create_index_bad_uid() { #[actix_rt::test] async fn create_index_bad_primary_key() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server .create_index(json!({ "uid": "doggo", "primaryKey": ["the", "best", "doggo"] })) @@ -114,7 +114,7 @@ async fn create_index_bad_primary_key() { #[actix_rt::test] async fn create_index_unknown_field() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.create_index(json!({ "uid": "doggo", "doggo": "bernese" })).await; snapshot!(code, @"400 Bad Request"); @@ -130,7 +130,7 @@ async fn create_index_unknown_field() { #[actix_rt::test] async fn get_index_bad_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("the good doggo"); let (response, code) = index.get().await; @@ -147,7 +147,7 @@ async fn get_index_bad_uid() { #[actix_rt::test] async fn update_index_bad_primary_key() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "primaryKey": ["doggo"] })).await; @@ -164,7 +164,7 @@ async fn update_index_bad_primary_key() { #[actix_rt::test] async fn update_index_immutable_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "uid": "doggo" })).await; @@ -181,7 +181,7 @@ async fn update_index_immutable_uid() { #[actix_rt::test] async fn update_index_immutable_created_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "createdAt": "doggo" })).await; @@ -198,7 +198,7 @@ async fn update_index_immutable_created_at() { #[actix_rt::test] async fn update_index_immutable_updated_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "updatedAt": "doggo" })).await; @@ -215,7 +215,7 @@ async fn update_index_immutable_updated_at() { #[actix_rt::test] async fn update_index_unknown_field() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "doggo": "bork" })).await; @@ -232,7 +232,7 @@ async fn update_index_unknown_field() { #[actix_rt::test] async fn update_index_bad_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("the good doggo"); let (response, code) = index.update_raw(json!({ "primaryKey": "doggo" })).await; @@ -249,7 +249,7 @@ async fn update_index_bad_uid() { #[actix_rt::test] async fn delete_index_bad_uid() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("the good doggo"); let (response, code) = index.delete().await; diff --git a/meilisearch/tests/logs/error.rs b/meilisearch/tests/logs/error.rs index 93dcccd66..81478595a 100644 --- a/meilisearch/tests/logs/error.rs +++ b/meilisearch/tests/logs/error.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn logs_stream_bad_target() { - let server = Server::new().await; + let server = Server::new_shared().await; // Wrong type let (response, code) = server.service.post("/logs/stream", json!({ "target": true })).await; @@ -58,7 +58,7 @@ async fn logs_stream_bad_target() { #[actix_rt::test] async fn logs_stream_bad_mode() { - let server = Server::new().await; + let server = Server::new_shared().await; // Wrong type let (response, code) = server.service.post("/logs/stream", json!({ "mode": true })).await; @@ -99,7 +99,7 @@ async fn logs_stream_bad_mode() { #[actix_rt::test] async fn logs_stream_bad_profile_memory() { - let server = Server::new().await; + let server = Server::new_shared().await; // Wrong type let (response, code) = @@ -156,7 +156,7 @@ async fn logs_stream_bad_profile_memory() { #[actix_rt::test] async fn logs_stream_without_enabling_the_route() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.service.post("/logs/stream", json!({})).await; snapshot!(code, @"400 Bad Request"); diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 5b15f66ba..557a62d1a 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -6,11 +6,11 @@ use crate::json; #[actix_rt::test] async fn search_unexisting_index() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.index("search_unexisting_index"); let expected_response = json!({ - "message": "Index `test` not found.", + "message": "Index `search_unexisting_index` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -26,8 +26,8 @@ async fn search_unexisting_index() { #[actix_rt::test] async fn search_unexisting_parameter() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index .search(json!({"marin": "hello"}), |response, code| { @@ -39,8 +39,8 @@ async fn search_unexisting_parameter() { #[actix_rt::test] async fn search_bad_q() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"q": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -57,8 +57,8 @@ async fn search_bad_q() { #[actix_rt::test] async fn search_bad_offset() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"offset": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -85,8 +85,8 @@ async fn search_bad_offset() { #[actix_rt::test] async fn search_bad_limit() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"limit": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -113,8 +113,8 @@ async fn search_bad_limit() { #[actix_rt::test] async fn search_bad_page() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"page": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -141,8 +141,8 @@ async fn search_bad_page() { #[actix_rt::test] async fn search_bad_hits_per_page() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"hitsPerPage": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -169,8 +169,8 @@ async fn search_bad_hits_per_page() { #[actix_rt::test] async fn search_bad_attributes_to_retrieve() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToRetrieve": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -187,8 +187,8 @@ async fn search_bad_attributes_to_retrieve() { #[actix_rt::test] async fn search_bad_retrieve_vectors() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"retrieveVectors": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -237,8 +237,8 @@ async fn search_bad_retrieve_vectors() { #[actix_rt::test] async fn search_bad_attributes_to_crop() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToCrop": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -255,8 +255,8 @@ async fn search_bad_attributes_to_crop() { #[actix_rt::test] async fn search_bad_crop_length() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"cropLength": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -283,8 +283,8 @@ async fn search_bad_crop_length() { #[actix_rt::test] async fn search_bad_attributes_to_highlight() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToHighlight": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -303,14 +303,12 @@ async fn search_bad_attributes_to_highlight() { async fn search_bad_filter() { // Since a filter is deserialized as a json Value it will never fail to deserialize. // Thus the error message is not generated by deserr but written by us. - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); // Also, to trigger the error message we need to effectively create the index or else it'll throw an // index does not exists error. - let (_, code) = index.create(None).await; - server.wait_task(0).await; - - snapshot!(code, @"202 Accepted"); + let (response, _code) = index.create(None).await; + server.wait_task(response.uid()).await.succeeded(); let (response, code) = index.search_post(json!({ "filter": true })).await; snapshot!(code, @"400 Bad Request"); @@ -327,8 +325,8 @@ async fn search_bad_filter() { #[actix_rt::test] async fn search_bad_sort() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"sort": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -345,8 +343,8 @@ async fn search_bad_sort() { #[actix_rt::test] async fn search_bad_show_matches_position() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"showMatchesPosition": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -373,8 +371,8 @@ async fn search_bad_show_matches_position() { #[actix_rt::test] async fn search_bad_facets() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"facets": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -391,8 +389,8 @@ async fn search_bad_facets() { #[actix_rt::test] async fn search_bad_threshold() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"rankingScoreThreshold": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -408,8 +406,8 @@ async fn search_bad_threshold() { #[actix_rt::test] async fn search_invalid_threshold() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"rankingScoreThreshold": 42})).await; snapshot!(code, @"400 Bad Request"); @@ -425,11 +423,11 @@ async fn search_invalid_threshold() { #[actix_rt::test] async fn search_non_filterable_facets() { - let server = Server::new().await; - let index = server.index("test"); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; + let server = Server::new_shared().await; + let index = server.unique_index(); + let (response, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; // Wait for the settings update to complete - index.wait_task(0).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -456,10 +454,11 @@ async fn search_non_filterable_facets() { #[actix_rt::test] async fn search_non_filterable_facets_multiple_filterable() { - let server = Server::new().await; - let index = server.index("test"); - index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; - index.wait_task(0).await; + let server = Server::new_shared().await; + let index = server.unique_index(); + let (response, _code) = + index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -486,10 +485,10 @@ async fn search_non_filterable_facets_multiple_filterable() { #[actix_rt::test] async fn search_non_filterable_facets_no_filterable() { - let server = Server::new().await; - let index = server.index("test"); - index.update_settings(json!({"filterableAttributes": []})).await; - index.wait_task(0).await; + let server = Server::new_shared().await; + let index = server.unique_index(); + let (response, _code) = index.update_settings(json!({"filterableAttributes": []})).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.search_post(json!({"facets": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -516,10 +515,11 @@ async fn search_non_filterable_facets_no_filterable() { #[actix_rt::test] async fn search_non_filterable_facets_multiple_facets() { - let server = Server::new().await; - let index = server.index("test"); - index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; - index.wait_task(0).await; + let server = Server::new_shared().await; + let index = server.unique_index(); + let (response, _uid) = + index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.search_post(json!({"facets": ["doggo", "neko"]})).await; snapshot!(code, @"400 Bad Request"); @@ -546,8 +546,8 @@ async fn search_non_filterable_facets_multiple_facets() { #[actix_rt::test] async fn search_bad_highlight_pre_tag() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"highlightPreTag": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -564,8 +564,8 @@ async fn search_bad_highlight_pre_tag() { #[actix_rt::test] async fn search_bad_highlight_post_tag() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"highlightPostTag": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -582,8 +582,8 @@ async fn search_bad_highlight_post_tag() { #[actix_rt::test] async fn search_bad_crop_marker() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"cropMarker": ["doggo"]})).await; snapshot!(code, @"400 Bad Request"); @@ -600,8 +600,8 @@ async fn search_bad_crop_marker() { #[actix_rt::test] async fn search_bad_matching_strategy() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (response, code) = index.search_post(json!({"matchingStrategy": "doggo"})).await; snapshot!(code, @"400 Bad Request"); @@ -639,8 +639,8 @@ async fn search_bad_matching_strategy() { #[actix_rt::test] async fn filter_invalid_syntax_object() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; @@ -665,8 +665,8 @@ async fn filter_invalid_syntax_object() { #[actix_rt::test] async fn filter_invalid_syntax_array() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; @@ -691,14 +691,14 @@ async fn filter_invalid_syntax_array() { #[actix_rt::test] async fn filter_invalid_syntax_string() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "Found unexpected characters at the end of the filter: `XOR title = Glass`. You probably forgot an `OR` or an `AND` rule.\n15:32 title = Glass XOR title = Glass", @@ -716,14 +716,14 @@ async fn filter_invalid_syntax_string() { #[actix_rt::test] async fn filter_invalid_attribute_array() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", @@ -741,14 +741,14 @@ async fn filter_invalid_attribute_array() { #[actix_rt::test] async fn filter_invalid_attribute_string() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", @@ -766,14 +766,14 @@ async fn filter_invalid_attribute_string() { #[actix_rt::test] async fn filter_reserved_geo_attribute_array() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -791,14 +791,14 @@ async fn filter_reserved_geo_attribute_array() { #[actix_rt::test] async fn filter_reserved_geo_attribute_string() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -816,14 +816,14 @@ async fn filter_reserved_geo_attribute_string() { #[actix_rt::test] async fn filter_reserved_attribute_array() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -841,14 +841,14 @@ async fn filter_reserved_attribute_array() { #[actix_rt::test] async fn filter_reserved_attribute_string() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -866,14 +866,14 @@ async fn filter_reserved_attribute_string() { #[actix_rt::test] async fn filter_reserved_geo_point_array() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", @@ -891,14 +891,14 @@ async fn filter_reserved_geo_point_array() { #[actix_rt::test] async fn filter_reserved_geo_point_string() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"filterableAttributes": ["title"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", @@ -916,14 +916,14 @@ async fn filter_reserved_geo_point_string() { #[actix_rt::test] async fn sort_geo_reserved_attribute() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"sortableAttributes": ["id"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a sort expression. Use the _geoPoint(latitude, longitude) built-in rule to sort on _geo field coordinates.", @@ -946,14 +946,14 @@ async fn sort_geo_reserved_attribute() { #[actix_rt::test] async fn sort_reserved_attribute() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"sortableAttributes": ["id"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a sort expression.", @@ -976,14 +976,14 @@ async fn sort_reserved_attribute() { #[actix_rt::test] async fn sort_unsortable_attribute() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.index("sort_unsortable_attribute"); index.update_settings(json!({"sortableAttributes": ["id"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ "message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.", @@ -1006,14 +1006,14 @@ async fn sort_unsortable_attribute() { #[actix_rt::test] async fn sort_invalid_syntax() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings(json!({"sortableAttributes": ["id"]})).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ "message": "Invalid syntax for the sort parameter: expected expression ending by `:asc` or `:desc`, found `title`.", @@ -1036,8 +1036,8 @@ async fn sort_invalid_syntax() { #[actix_rt::test] async fn sort_unset_ranking_rule() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index .update_settings( @@ -1046,8 +1046,8 @@ async fn sort_unset_ranking_rule() { .await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ "message": "You must specify where `sort` is listed in the rankingRules setting to use the sort parameter at search time.", @@ -1070,14 +1070,13 @@ async fn sort_unset_ranking_rule() { #[actix_rt::test] async fn search_on_unknown_field() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings_searchable_attributes(json!(["id", "title"])).await; - index.wait_task(0).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); index .search( @@ -1099,14 +1098,13 @@ async fn search_on_unknown_field() { #[actix_rt::test] async fn search_on_unknown_field_plus_joker() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared().await; + let index = server.unique_index(); index.update_settings_searchable_attributes(json!(["id", "title"])).await; - index.wait_task(0).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); index .search( @@ -1145,11 +1143,10 @@ async fn search_on_unknown_field_plus_joker() { #[actix_rt::test] async fn distinct_at_search_time() { - let server = Server::new().await; - let index = server.index("tamo"); + let server = Server::new_shared().await; + let index = server.unique_index(); let (task, _) = index.create(None).await; - let task = index.wait_task(task.uid()).await; - snapshot!(task, name: "task-succeed"); + index.wait_task(task.uid()).await.succeeded(); let (response, code) = index.search_post(json!({"page": 0, "hitsPerPage": 2, "distinct": "doggo.truc"})).await; @@ -1210,8 +1207,8 @@ async fn distinct_at_search_time() { async fn search_with_contains_without_enabling_the_feature() { // Since a filter is deserialized as a json Value it will never fail to deserialize. // Thus the error message is not generated by deserr but written by us. - let server = Server::new().await; - let index = server.index("doggo"); + let server = Server::new_shared().await; + let index = server.unique_index(); // Also, to trigger the error message we need to effectively create the index or else it'll throw an // index does not exists error. let (task, _code) = index.create(None).await; diff --git a/meilisearch/tests/search/snapshots/distinct.rs/distinct_at_search_time/succeed.snap b/meilisearch/tests/search/snapshots/distinct.rs/distinct_at_search_time/succeed.snap index 1b8190c42..64e48b6a5 100644 --- a/meilisearch/tests/search/snapshots/distinct.rs/distinct_at_search_time/succeed.snap +++ b/meilisearch/tests/search/snapshots/distinct.rs/distinct_at_search_time/succeed.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/search/distinct.rs --- { - "uid": 1, + "uid": "[uid]", "indexUid": "tamo", "status": "succeeded", "type": "settingsUpdate", diff --git a/meilisearch/tests/settings/errors.rs b/meilisearch/tests/settings/errors.rs index 2bd17d649..906d66dd0 100644 --- a/meilisearch/tests/settings/errors.rs +++ b/meilisearch/tests/settings/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn settings_bad_displayed_attributes() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "displayedAttributes": "doggo" })).await; @@ -33,7 +33,7 @@ async fn settings_bad_displayed_attributes() { #[actix_rt::test] async fn settings_bad_searchable_attributes() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "searchableAttributes": "doggo" })).await; @@ -61,7 +61,7 @@ async fn settings_bad_searchable_attributes() { #[actix_rt::test] async fn settings_bad_filterable_attributes() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "filterableAttributes": "doggo" })).await; @@ -89,7 +89,7 @@ async fn settings_bad_filterable_attributes() { #[actix_rt::test] async fn settings_bad_sortable_attributes() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "sortableAttributes": "doggo" })).await; @@ -117,7 +117,7 @@ async fn settings_bad_sortable_attributes() { #[actix_rt::test] async fn settings_bad_ranking_rules() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "rankingRules": "doggo" })).await; @@ -145,7 +145,7 @@ async fn settings_bad_ranking_rules() { #[actix_rt::test] async fn settings_bad_stop_words() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "stopWords": "doggo" })).await; @@ -173,7 +173,7 @@ async fn settings_bad_stop_words() { #[actix_rt::test] async fn settings_bad_synonyms() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "synonyms": "doggo" })).await; @@ -201,7 +201,7 @@ async fn settings_bad_synonyms() { #[actix_rt::test] async fn settings_bad_distinct_attribute() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "distinctAttribute": ["doggo"] })).await; @@ -229,7 +229,7 @@ async fn settings_bad_distinct_attribute() { #[actix_rt::test] async fn settings_bad_typo_tolerance() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "typoTolerance": "doggo" })).await; @@ -284,7 +284,7 @@ async fn settings_bad_typo_tolerance() { #[actix_rt::test] async fn settings_bad_faceting() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "faceting": "doggo" })).await; @@ -312,7 +312,7 @@ async fn settings_bad_faceting() { #[actix_rt::test] async fn settings_bad_pagination() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "pagination": "doggo" })).await; @@ -340,7 +340,7 @@ async fn settings_bad_pagination() { #[actix_rt::test] async fn settings_bad_search_cutoff_ms() { - let server = Server::new().await; + let server = Server::new_shared().await; let index = server.index("test"); let (response, code) = index.update_settings(json!({ "searchCutoffMs": "doggo" })).await; diff --git a/meilisearch/tests/swap_indexes/errors.rs b/meilisearch/tests/swap_indexes/errors.rs index d8fa85b3a..d1869854e 100644 --- a/meilisearch/tests/swap_indexes/errors.rs +++ b/meilisearch/tests/swap_indexes/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn swap_indexes_bad_format() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.index_swap(json!("doggo")).await; snapshot!(code, @"400 Bad Request"); @@ -32,7 +32,7 @@ async fn swap_indexes_bad_format() { #[actix_rt::test] async fn swap_indexes_bad_indexes() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.index_swap(json!([{ "indexes": "doggo"}])).await; snapshot!(code, @"400 Bad Request"); diff --git a/meilisearch/tests/tasks/errors.rs b/meilisearch/tests/tasks/errors.rs index 2c85acf0e..9a4f72d62 100644 --- a/meilisearch/tests/tasks/errors.rs +++ b/meilisearch/tests/tasks/errors.rs @@ -4,7 +4,7 @@ use crate::common::Server; #[actix_rt::test] async fn task_bad_uids() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("uids=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -53,7 +53,7 @@ async fn task_bad_uids() { #[actix_rt::test] async fn task_bad_canceled_by() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("canceledBy=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -91,7 +91,7 @@ async fn task_bad_canceled_by() { #[actix_rt::test] async fn task_bad_types() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("types=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -129,7 +129,7 @@ async fn task_bad_types() { #[actix_rt::test] async fn task_bad_statuses() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("statuses=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -167,7 +167,7 @@ async fn task_bad_statuses() { #[actix_rt::test] async fn task_bad_index_uids() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("indexUids=the%20good%20doggo").await; snapshot!(code, @"400 Bad Request"); @@ -205,7 +205,7 @@ async fn task_bad_index_uids() { #[actix_rt::test] async fn task_bad_limit() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("limit=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -243,7 +243,7 @@ async fn task_bad_limit() { #[actix_rt::test] async fn task_bad_from() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("from=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -281,7 +281,7 @@ async fn task_bad_from() { #[actix_rt::test] async fn task_bad_after_enqueued_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("afterEnqueuedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -319,7 +319,7 @@ async fn task_bad_after_enqueued_at() { #[actix_rt::test] async fn task_bad_before_enqueued_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("beforeEnqueuedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -357,7 +357,7 @@ async fn task_bad_before_enqueued_at() { #[actix_rt::test] async fn task_bad_after_started_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("afterStartedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -395,7 +395,7 @@ async fn task_bad_after_started_at() { #[actix_rt::test] async fn task_bad_before_started_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("beforeStartedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -433,7 +433,7 @@ async fn task_bad_before_started_at() { #[actix_rt::test] async fn task_bad_after_finished_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("afterFinishedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -471,7 +471,7 @@ async fn task_bad_after_finished_at() { #[actix_rt::test] async fn task_bad_before_finished_at() { - let server = Server::new().await; + let server = Server::new_shared().await; let (response, code) = server.tasks_filter("beforeFinishedAt=doggo").await; snapshot!(code, @"400 Bad Request"); diff --git a/meilisearch/tests/tasks/mod.rs b/meilisearch/tests/tasks/mod.rs index f2ed76b6a..23ba669ca 100644 --- a/meilisearch/tests/tasks/mod.rs +++ b/meilisearch/tests/tasks/mod.rs @@ -744,7 +744,7 @@ async fn test_summarized_index_deletion() { snapshot!(task, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "test", "status": "failed", "type": "indexDeletion", @@ -774,7 +774,7 @@ async fn test_summarized_index_deletion() { snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -796,7 +796,7 @@ async fn test_summarized_index_deletion() { snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "test", "status": "succeeded", "type": "indexDeletion", @@ -818,7 +818,7 @@ async fn test_summarized_index_deletion() { snapshot!(task, @r###" { - "uid": 3, + "uid": "[uid]", "indexUid": "test", "status": "failed", "type": "indexDeletion", diff --git a/meilisearch/tests/vector/mod.rs b/meilisearch/tests/vector/mod.rs index 4a142f86a..79bc41d19 100644 --- a/meilisearch/tests/vector/mod.rs +++ b/meilisearch/tests/vector/mod.rs @@ -218,7 +218,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -247,7 +247,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 3, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -277,7 +277,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 4, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -306,7 +306,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 5, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -335,7 +335,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 6, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -364,7 +364,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 7, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -405,7 +405,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 10, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -433,7 +433,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 11, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -461,7 +461,7 @@ async fn user_provided_embeddings_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 12, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -497,7 +497,7 @@ async fn user_provided_vectors_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -526,7 +526,7 @@ async fn user_provided_vectors_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 3, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -555,7 +555,7 @@ async fn user_provided_vectors_error() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 4, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", diff --git a/meilisearch/tests/vector/rest.rs b/meilisearch/tests/vector/rest.rs index 71d3c7cda..370c1ecf7 100644 --- a/meilisearch/tests/vector/rest.rs +++ b/meilisearch/tests/vector/rest.rs @@ -896,7 +896,7 @@ async fn bad_settings() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -990,7 +990,7 @@ async fn add_vector_and_user_provided() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1086,7 +1086,7 @@ async fn server_returns_bad_request() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1198,7 +1198,7 @@ async fn server_returns_bad_response() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1251,7 +1251,7 @@ async fn server_returns_bad_response() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1306,7 +1306,7 @@ async fn server_returns_bad_response() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1361,7 +1361,7 @@ async fn server_returns_bad_response() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 3, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1426,7 +1426,7 @@ async fn server_returns_bad_response() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 4, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1493,7 +1493,7 @@ async fn server_returns_multiple() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1598,7 +1598,7 @@ async fn server_single_input_returns_in_array() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1703,7 +1703,7 @@ async fn server_raw() { let task = index.wait_task(value.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", @@ -1800,7 +1800,7 @@ async fn server_custom_header() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 0, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", diff --git a/meilisearch/tests/vector/settings.rs b/meilisearch/tests/vector/settings.rs index 8fdb858c3..0714a22ca 100644 --- a/meilisearch/tests/vector/settings.rs +++ b/meilisearch/tests/vector/settings.rs @@ -43,7 +43,7 @@ async fn update_embedder() { let ret = server.wait_task(response.uid()).await; snapshot!(ret, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "settingsUpdate", diff --git a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-added.snap b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-added.snap index 52d9ad38d..c4f1c0b25 100644 --- a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-added.snap +++ b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-added.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/vector/mod.rs --- { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", diff --git a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-deleted.snap b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-deleted.snap index de02d0b1d..c4f1c0b25 100644 --- a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-deleted.snap +++ b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/document-deleted.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/vector/mod.rs --- { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "documentAdditionOrUpdate", diff --git a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/settings-processed.snap b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/settings-processed.snap index 316305fa8..08dbe3ee0 100644 --- a/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/settings-processed.snap +++ b/meilisearch/tests/vector/snapshots/mod.rs/add_remove_one_vector_4588/settings-processed.snap @@ -2,7 +2,7 @@ source: meilisearch/tests/vector/mod.rs --- { - "uid": 0, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "settingsUpdate", From 953d3a44bd92f359165ffa77b8bdfbec3b3535bd Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 17:26:43 +0200 Subject: [PATCH 04/15] make the new_shared function synchronous and stop indexing documents when it's not required --- meilisearch/tests/common/server.rs | 2 +- meilisearch/tests/documents/errors.rs | 34 ++--- meilisearch/tests/index/errors.rs | 30 ++-- meilisearch/tests/logs/error.rs | 8 +- meilisearch/tests/search/errors.rs | 185 ++++++++--------------- meilisearch/tests/settings/errors.rs | 24 +-- meilisearch/tests/swap_indexes/errors.rs | 4 +- meilisearch/tests/tasks/errors.rs | 26 ++-- 8 files changed, 130 insertions(+), 183 deletions(-) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index ffa455892..28ddbe754 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -51,7 +51,7 @@ impl Server { Server { service, _dir: Some(dir) } } - pub async fn new_shared() -> &'static Self { + pub fn new_shared() -> &'static Self { &TEST_SHARED_INSTANCE } diff --git a/meilisearch/tests/documents/errors.rs b/meilisearch/tests/documents/errors.rs index 600b3b272..2d2c2bd6b 100644 --- a/meilisearch/tests/documents/errors.rs +++ b/meilisearch/tests/documents/errors.rs @@ -6,7 +6,7 @@ use crate::json; #[actix_rt::test] async fn get_all_documents_bad_offset() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.get_all_documents_raw("?offset").await; @@ -45,7 +45,7 @@ async fn get_all_documents_bad_offset() { #[actix_rt::test] async fn get_all_documents_bad_limit() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.get_all_documents_raw("?limit").await; @@ -84,7 +84,7 @@ async fn get_all_documents_bad_limit() { #[actix_rt::test] async fn get_all_documents_bad_filter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); // Since the filter can't be parsed automatically by deserr, we have the wrong error message @@ -162,7 +162,7 @@ async fn get_all_documents_bad_filter() { #[actix_rt::test] async fn delete_documents_batch() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.delete_batch_raw(json!("doggo")).await; @@ -179,7 +179,7 @@ async fn delete_documents_batch() { #[actix_rt::test] async fn replace_documents_missing_payload() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = @@ -221,7 +221,7 @@ async fn replace_documents_missing_payload() { #[actix_rt::test] async fn update_documents_missing_payload() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.raw_update_documents("", Some("application/json"), "").await; @@ -260,7 +260,7 @@ async fn update_documents_missing_payload() { #[actix_rt::test] async fn replace_documents_missing_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.raw_add_documents("", Vec::new(), "").await; @@ -289,7 +289,7 @@ async fn replace_documents_missing_content_type() { #[actix_rt::test] async fn update_documents_missing_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.raw_update_documents("", None, "").await; @@ -318,7 +318,7 @@ async fn update_documents_missing_content_type() { #[actix_rt::test] async fn replace_documents_bad_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.raw_add_documents("", vec![("Content-Type", "doggo")], "").await; @@ -335,7 +335,7 @@ async fn replace_documents_bad_content_type() { #[actix_rt::test] async fn update_documents_bad_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.raw_update_documents("", Some("doggo"), "").await; @@ -352,7 +352,7 @@ async fn update_documents_bad_content_type() { #[actix_rt::test] async fn replace_documents_bad_csv_delimiter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index @@ -401,7 +401,7 @@ async fn replace_documents_bad_csv_delimiter() { #[actix_rt::test] async fn update_documents_bad_csv_delimiter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = @@ -448,7 +448,7 @@ async fn update_documents_bad_csv_delimiter() { #[actix_rt::test] async fn replace_documents_csv_delimiter_with_bad_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index @@ -480,7 +480,7 @@ async fn replace_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn update_documents_csv_delimiter_with_bad_content_type() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = @@ -510,7 +510,7 @@ async fn update_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn delete_document_by_filter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("tests-documents-errors-delete_document_by_filter"); // send a bad payload type @@ -674,7 +674,7 @@ async fn delete_document_by_filter() { #[actix_rt::test] async fn fetch_document_by_filter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); index.update_settings_filterable_attributes(json!(["color"])).await; index @@ -771,7 +771,7 @@ async fn fetch_document_by_filter() { #[actix_rt::test] async fn retrieve_vectors() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); // GET ALL DOCUMENTS BY QUERY diff --git a/meilisearch/tests/index/errors.rs b/meilisearch/tests/index/errors.rs index 88e197323..bccfd4a90 100644 --- a/meilisearch/tests/index/errors.rs +++ b/meilisearch/tests/index/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn get_indexes_bad_offset() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.list_indexes_raw("?offset=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -21,7 +21,7 @@ async fn get_indexes_bad_offset() { #[actix_rt::test] async fn get_indexes_bad_limit() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.list_indexes_raw("?limit=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -37,7 +37,7 @@ async fn get_indexes_bad_limit() { #[actix_rt::test] async fn get_indexes_unknown_field() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.list_indexes_raw("?doggo=nolimit").await; snapshot!(code, @"400 Bad Request"); @@ -53,7 +53,7 @@ async fn get_indexes_unknown_field() { #[actix_rt::test] async fn create_index_missing_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.create_index(json!({ "primaryKey": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -69,7 +69,7 @@ async fn create_index_missing_uid() { #[actix_rt::test] async fn create_index_bad_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.create_index(json!({ "uid": "the best doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -96,7 +96,7 @@ async fn create_index_bad_uid() { #[actix_rt::test] async fn create_index_bad_primary_key() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server .create_index(json!({ "uid": "doggo", "primaryKey": ["the", "best", "doggo"] })) @@ -114,7 +114,7 @@ async fn create_index_bad_primary_key() { #[actix_rt::test] async fn create_index_unknown_field() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.create_index(json!({ "uid": "doggo", "doggo": "bernese" })).await; snapshot!(code, @"400 Bad Request"); @@ -130,7 +130,7 @@ async fn create_index_unknown_field() { #[actix_rt::test] async fn get_index_bad_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("the good doggo"); let (response, code) = index.get().await; @@ -147,7 +147,7 @@ async fn get_index_bad_uid() { #[actix_rt::test] async fn update_index_bad_primary_key() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "primaryKey": ["doggo"] })).await; @@ -164,7 +164,7 @@ async fn update_index_bad_primary_key() { #[actix_rt::test] async fn update_index_immutable_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "uid": "doggo" })).await; @@ -181,7 +181,7 @@ async fn update_index_immutable_uid() { #[actix_rt::test] async fn update_index_immutable_created_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "createdAt": "doggo" })).await; @@ -198,7 +198,7 @@ async fn update_index_immutable_created_at() { #[actix_rt::test] async fn update_index_immutable_updated_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "updatedAt": "doggo" })).await; @@ -215,7 +215,7 @@ async fn update_index_immutable_updated_at() { #[actix_rt::test] async fn update_index_unknown_field() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("doggo"); let (response, code) = index.update_raw(json!({ "doggo": "bork" })).await; @@ -232,7 +232,7 @@ async fn update_index_unknown_field() { #[actix_rt::test] async fn update_index_bad_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("the good doggo"); let (response, code) = index.update_raw(json!({ "primaryKey": "doggo" })).await; @@ -249,7 +249,7 @@ async fn update_index_bad_uid() { #[actix_rt::test] async fn delete_index_bad_uid() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("the good doggo"); let (response, code) = index.delete().await; diff --git a/meilisearch/tests/logs/error.rs b/meilisearch/tests/logs/error.rs index 81478595a..2cc94800e 100644 --- a/meilisearch/tests/logs/error.rs +++ b/meilisearch/tests/logs/error.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn logs_stream_bad_target() { - let server = Server::new_shared().await; + let server = Server::new_shared(); // Wrong type let (response, code) = server.service.post("/logs/stream", json!({ "target": true })).await; @@ -58,7 +58,7 @@ async fn logs_stream_bad_target() { #[actix_rt::test] async fn logs_stream_bad_mode() { - let server = Server::new_shared().await; + let server = Server::new_shared(); // Wrong type let (response, code) = server.service.post("/logs/stream", json!({ "mode": true })).await; @@ -99,7 +99,7 @@ async fn logs_stream_bad_mode() { #[actix_rt::test] async fn logs_stream_bad_profile_memory() { - let server = Server::new_shared().await; + let server = Server::new_shared(); // Wrong type let (response, code) = @@ -156,7 +156,7 @@ async fn logs_stream_bad_profile_memory() { #[actix_rt::test] async fn logs_stream_without_enabling_the_route() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.service.post("/logs/stream", json!({})).await; snapshot!(code, @"400 Bad Request"); diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 557a62d1a..2dbb80f6e 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -1,12 +1,11 @@ use meili_snap::*; -use super::DOCUMENTS; use crate::common::Server; use crate::json; #[actix_rt::test] async fn search_unexisting_index() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("search_unexisting_index"); let expected_response = json!({ @@ -26,7 +25,7 @@ async fn search_unexisting_index() { #[actix_rt::test] async fn search_unexisting_parameter() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); index @@ -39,7 +38,7 @@ async fn search_unexisting_parameter() { #[actix_rt::test] async fn search_bad_q() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"q": ["doggo"]})).await; @@ -57,7 +56,7 @@ async fn search_bad_q() { #[actix_rt::test] async fn search_bad_offset() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"offset": "doggo"})).await; @@ -85,7 +84,7 @@ async fn search_bad_offset() { #[actix_rt::test] async fn search_bad_limit() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"limit": "doggo"})).await; @@ -113,7 +112,7 @@ async fn search_bad_limit() { #[actix_rt::test] async fn search_bad_page() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"page": "doggo"})).await; @@ -141,7 +140,7 @@ async fn search_bad_page() { #[actix_rt::test] async fn search_bad_hits_per_page() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"hitsPerPage": "doggo"})).await; @@ -169,7 +168,7 @@ async fn search_bad_hits_per_page() { #[actix_rt::test] async fn search_bad_attributes_to_retrieve() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToRetrieve": "doggo"})).await; @@ -187,7 +186,7 @@ async fn search_bad_attributes_to_retrieve() { #[actix_rt::test] async fn search_bad_retrieve_vectors() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"retrieveVectors": "doggo"})).await; @@ -237,7 +236,7 @@ async fn search_bad_retrieve_vectors() { #[actix_rt::test] async fn search_bad_attributes_to_crop() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToCrop": "doggo"})).await; @@ -255,7 +254,7 @@ async fn search_bad_attributes_to_crop() { #[actix_rt::test] async fn search_bad_crop_length() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"cropLength": "doggo"})).await; @@ -283,7 +282,7 @@ async fn search_bad_crop_length() { #[actix_rt::test] async fn search_bad_attributes_to_highlight() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"attributesToHighlight": "doggo"})).await; @@ -303,7 +302,7 @@ async fn search_bad_attributes_to_highlight() { async fn search_bad_filter() { // Since a filter is deserialized as a json Value it will never fail to deserialize. // Thus the error message is not generated by deserr but written by us. - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); // Also, to trigger the error message we need to effectively create the index or else it'll throw an // index does not exists error. @@ -325,7 +324,7 @@ async fn search_bad_filter() { #[actix_rt::test] async fn search_bad_sort() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"sort": "doggo"})).await; @@ -343,7 +342,7 @@ async fn search_bad_sort() { #[actix_rt::test] async fn search_bad_show_matches_position() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"showMatchesPosition": "doggo"})).await; @@ -371,7 +370,7 @@ async fn search_bad_show_matches_position() { #[actix_rt::test] async fn search_bad_facets() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"facets": "doggo"})).await; @@ -389,7 +388,7 @@ async fn search_bad_facets() { #[actix_rt::test] async fn search_bad_threshold() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"rankingScoreThreshold": "doggo"})).await; @@ -406,7 +405,7 @@ async fn search_bad_threshold() { #[actix_rt::test] async fn search_invalid_threshold() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"rankingScoreThreshold": 42})).await; @@ -423,7 +422,7 @@ async fn search_invalid_threshold() { #[actix_rt::test] async fn search_non_filterable_facets() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; // Wait for the settings update to complete @@ -454,7 +453,7 @@ async fn search_non_filterable_facets() { #[actix_rt::test] async fn search_non_filterable_facets_multiple_filterable() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, _code) = index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; @@ -485,7 +484,7 @@ async fn search_non_filterable_facets_multiple_filterable() { #[actix_rt::test] async fn search_non_filterable_facets_no_filterable() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, _code) = index.update_settings(json!({"filterableAttributes": []})).await; index.wait_task(response.uid()).await.succeeded(); @@ -515,7 +514,7 @@ async fn search_non_filterable_facets_no_filterable() { #[actix_rt::test] async fn search_non_filterable_facets_multiple_facets() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, _uid) = index.update_settings(json!({"filterableAttributes": ["title", "genres"]})).await; @@ -546,7 +545,7 @@ async fn search_non_filterable_facets_multiple_facets() { #[actix_rt::test] async fn search_bad_highlight_pre_tag() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"highlightPreTag": ["doggo"]})).await; @@ -564,7 +563,7 @@ async fn search_bad_highlight_pre_tag() { #[actix_rt::test] async fn search_bad_highlight_post_tag() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"highlightPostTag": ["doggo"]})).await; @@ -582,7 +581,7 @@ async fn search_bad_highlight_post_tag() { #[actix_rt::test] async fn search_bad_crop_marker() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"cropMarker": ["doggo"]})).await; @@ -600,7 +599,7 @@ async fn search_bad_crop_marker() { #[actix_rt::test] async fn search_bad_matching_strategy() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (response, code) = index.search_post(json!({"matchingStrategy": "doggo"})).await; @@ -639,13 +638,10 @@ async fn search_bad_matching_strategy() { #[actix_rt::test] async fn filter_invalid_syntax_object() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; index @@ -665,13 +661,10 @@ async fn filter_invalid_syntax_object() { #[actix_rt::test] async fn filter_invalid_syntax_array() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; index @@ -691,13 +684,10 @@ async fn filter_invalid_syntax_array() { #[actix_rt::test] async fn filter_invalid_syntax_string() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -716,13 +706,10 @@ async fn filter_invalid_syntax_string() { #[actix_rt::test] async fn filter_invalid_attribute_array() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -741,13 +728,10 @@ async fn filter_invalid_attribute_array() { #[actix_rt::test] async fn filter_invalid_attribute_string() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -766,13 +750,10 @@ async fn filter_invalid_attribute_string() { #[actix_rt::test] async fn filter_reserved_geo_attribute_array() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -791,13 +772,10 @@ async fn filter_reserved_geo_attribute_array() { #[actix_rt::test] async fn filter_reserved_geo_attribute_string() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -816,13 +794,10 @@ async fn filter_reserved_geo_attribute_string() { #[actix_rt::test] async fn filter_reserved_attribute_array() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -841,13 +816,10 @@ async fn filter_reserved_attribute_array() { #[actix_rt::test] async fn filter_reserved_attribute_string() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -866,13 +838,10 @@ async fn filter_reserved_attribute_string() { #[actix_rt::test] async fn filter_reserved_geo_point_array() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -891,13 +860,10 @@ async fn filter_reserved_geo_point_array() { #[actix_rt::test] async fn filter_reserved_geo_point_string() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -916,13 +882,10 @@ async fn filter_reserved_geo_point_string() { #[actix_rt::test] async fn sort_geo_reserved_attribute() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"sortableAttributes": ["id"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -946,13 +909,10 @@ async fn sort_geo_reserved_attribute() { #[actix_rt::test] async fn sort_reserved_attribute() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"sortableAttributes": ["id"]})).await; - - let documents = DOCUMENTS.clone(); - let (task, _code) = index.add_documents(documents, None).await; + let (task, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; index.wait_task(task.uid()).await; let expected_response = json!({ @@ -976,13 +936,10 @@ async fn sort_reserved_attribute() { #[actix_rt::test] async fn sort_unsortable_attribute() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("sort_unsortable_attribute"); - index.update_settings(json!({"sortableAttributes": ["id"]})).await; - - let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; + let (response, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ @@ -1006,13 +963,10 @@ async fn sort_unsortable_attribute() { #[actix_rt::test] async fn sort_invalid_syntax() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings(json!({"sortableAttributes": ["id"]})).await; - - let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; + let (response, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ @@ -1036,17 +990,14 @@ async fn sort_invalid_syntax() { #[actix_rt::test] async fn sort_unset_ranking_rule() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index + let (response, _code) = index .update_settings( json!({"sortableAttributes": ["title"], "rankingRules": ["proximity", "exactness"]}), ) .await; - - let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; index.wait_task(response.uid()).await.succeeded(); let expected_response = json!({ @@ -1070,12 +1021,10 @@ async fn sort_unset_ranking_rule() { #[actix_rt::test] async fn search_on_unknown_field() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings_searchable_attributes(json!(["id", "title"])).await; - - let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; + let (response, _code) = + index.update_settings_searchable_attributes(json!(["id", "title"])).await; index.wait_task(response.uid()).await.succeeded(); index @@ -1098,12 +1047,10 @@ async fn search_on_unknown_field() { #[actix_rt::test] async fn search_on_unknown_field_plus_joker() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); - index.update_settings_searchable_attributes(json!(["id", "title"])).await; - - let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; + let (response, _code) = + index.update_settings_searchable_attributes(json!(["id", "title"])).await; index.wait_task(response.uid()).await.succeeded(); index @@ -1143,7 +1090,7 @@ async fn search_on_unknown_field_plus_joker() { #[actix_rt::test] async fn distinct_at_search_time() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); let (task, _) = index.create(None).await; index.wait_task(task.uid()).await.succeeded(); @@ -1207,7 +1154,7 @@ async fn distinct_at_search_time() { async fn search_with_contains_without_enabling_the_feature() { // Since a filter is deserialized as a json Value it will never fail to deserialize. // Thus the error message is not generated by deserr but written by us. - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.unique_index(); // Also, to trigger the error message we need to effectively create the index or else it'll throw an // index does not exists error. diff --git a/meilisearch/tests/settings/errors.rs b/meilisearch/tests/settings/errors.rs index 906d66dd0..c0dc1975a 100644 --- a/meilisearch/tests/settings/errors.rs +++ b/meilisearch/tests/settings/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn settings_bad_displayed_attributes() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "displayedAttributes": "doggo" })).await; @@ -33,7 +33,7 @@ async fn settings_bad_displayed_attributes() { #[actix_rt::test] async fn settings_bad_searchable_attributes() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "searchableAttributes": "doggo" })).await; @@ -61,7 +61,7 @@ async fn settings_bad_searchable_attributes() { #[actix_rt::test] async fn settings_bad_filterable_attributes() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "filterableAttributes": "doggo" })).await; @@ -89,7 +89,7 @@ async fn settings_bad_filterable_attributes() { #[actix_rt::test] async fn settings_bad_sortable_attributes() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "sortableAttributes": "doggo" })).await; @@ -117,7 +117,7 @@ async fn settings_bad_sortable_attributes() { #[actix_rt::test] async fn settings_bad_ranking_rules() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "rankingRules": "doggo" })).await; @@ -145,7 +145,7 @@ async fn settings_bad_ranking_rules() { #[actix_rt::test] async fn settings_bad_stop_words() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "stopWords": "doggo" })).await; @@ -173,7 +173,7 @@ async fn settings_bad_stop_words() { #[actix_rt::test] async fn settings_bad_synonyms() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "synonyms": "doggo" })).await; @@ -201,7 +201,7 @@ async fn settings_bad_synonyms() { #[actix_rt::test] async fn settings_bad_distinct_attribute() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "distinctAttribute": ["doggo"] })).await; @@ -229,7 +229,7 @@ async fn settings_bad_distinct_attribute() { #[actix_rt::test] async fn settings_bad_typo_tolerance() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "typoTolerance": "doggo" })).await; @@ -284,7 +284,7 @@ async fn settings_bad_typo_tolerance() { #[actix_rt::test] async fn settings_bad_faceting() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "faceting": "doggo" })).await; @@ -312,7 +312,7 @@ async fn settings_bad_faceting() { #[actix_rt::test] async fn settings_bad_pagination() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "pagination": "doggo" })).await; @@ -340,7 +340,7 @@ async fn settings_bad_pagination() { #[actix_rt::test] async fn settings_bad_search_cutoff_ms() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let index = server.index("test"); let (response, code) = index.update_settings(json!({ "searchCutoffMs": "doggo" })).await; diff --git a/meilisearch/tests/swap_indexes/errors.rs b/meilisearch/tests/swap_indexes/errors.rs index d1869854e..d136dfc0f 100644 --- a/meilisearch/tests/swap_indexes/errors.rs +++ b/meilisearch/tests/swap_indexes/errors.rs @@ -5,7 +5,7 @@ use crate::json; #[actix_rt::test] async fn swap_indexes_bad_format() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.index_swap(json!("doggo")).await; snapshot!(code, @"400 Bad Request"); @@ -32,7 +32,7 @@ async fn swap_indexes_bad_format() { #[actix_rt::test] async fn swap_indexes_bad_indexes() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.index_swap(json!([{ "indexes": "doggo"}])).await; snapshot!(code, @"400 Bad Request"); diff --git a/meilisearch/tests/tasks/errors.rs b/meilisearch/tests/tasks/errors.rs index 9a4f72d62..c404a2329 100644 --- a/meilisearch/tests/tasks/errors.rs +++ b/meilisearch/tests/tasks/errors.rs @@ -4,7 +4,7 @@ use crate::common::Server; #[actix_rt::test] async fn task_bad_uids() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("uids=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -53,7 +53,7 @@ async fn task_bad_uids() { #[actix_rt::test] async fn task_bad_canceled_by() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("canceledBy=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -91,7 +91,7 @@ async fn task_bad_canceled_by() { #[actix_rt::test] async fn task_bad_types() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("types=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -129,7 +129,7 @@ async fn task_bad_types() { #[actix_rt::test] async fn task_bad_statuses() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("statuses=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -167,7 +167,7 @@ async fn task_bad_statuses() { #[actix_rt::test] async fn task_bad_index_uids() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("indexUids=the%20good%20doggo").await; snapshot!(code, @"400 Bad Request"); @@ -205,7 +205,7 @@ async fn task_bad_index_uids() { #[actix_rt::test] async fn task_bad_limit() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("limit=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -243,7 +243,7 @@ async fn task_bad_limit() { #[actix_rt::test] async fn task_bad_from() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("from=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -281,7 +281,7 @@ async fn task_bad_from() { #[actix_rt::test] async fn task_bad_after_enqueued_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("afterEnqueuedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -319,7 +319,7 @@ async fn task_bad_after_enqueued_at() { #[actix_rt::test] async fn task_bad_before_enqueued_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("beforeEnqueuedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -357,7 +357,7 @@ async fn task_bad_before_enqueued_at() { #[actix_rt::test] async fn task_bad_after_started_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("afterStartedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -395,7 +395,7 @@ async fn task_bad_after_started_at() { #[actix_rt::test] async fn task_bad_before_started_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("beforeStartedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -433,7 +433,7 @@ async fn task_bad_before_started_at() { #[actix_rt::test] async fn task_bad_after_finished_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("afterFinishedAt=doggo").await; snapshot!(code, @"400 Bad Request"); @@ -471,7 +471,7 @@ async fn task_bad_after_finished_at() { #[actix_rt::test] async fn task_bad_before_finished_at() { - let server = Server::new_shared().await; + let server = Server::new_shared(); let (response, code) = server.tasks_filter("beforeFinishedAt=doggo").await; snapshot!(code, @"400 Bad Request"); From 993264227d43bb8c3208890ee344a892650726f3 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 18:13:42 +0200 Subject: [PATCH 05/15] reuse an index with already indexed documents instead of reindexing from scratch --- meilisearch/tests/search/mod.rs | 196 ++++++------------ meilisearch/tests/search/multi.rs | 2 +- meilisearch/tests/search/pagination.rs | 55 ++--- .../tests/search/restrict_searchable.rs | 4 +- 4 files changed, 81 insertions(+), 176 deletions(-) diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index 301ef9aa2..77be4c13a 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -17,7 +17,9 @@ mod search_queue; use meilisearch::Opt; use once_cell::sync::Lazy; use tempfile::TempDir; +use uuid::Uuid; +use crate::common::index::Index; use crate::common::{default_settings, Server, Value}; use crate::json; @@ -51,6 +53,29 @@ static DOCUMENTS: Lazy = Lazy::new(|| { ]) }); +pub async fn shared_index_with_documents() -> &'static Index<'static> { + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + let uuid = Uuid::new_v4(); + let index = server.index(uuid.to_string()); + index + }); + let index = Lazy::get(&INDEX); + // That means the lazy has never been initialized, we need to create the index and index the documents + if index.is_none() { + let documents = DOCUMENTS.clone(); + let (response, _code) = INDEX.add_documents(documents, None).await; + INDEX.wait_task(response.uid()).await.succeeded(); + let (response, _code) = INDEX + .update_settings( + json!({"filterableAttributes": ["id", "title"], "sortableAttributes": ["id", "title"]}), + ) + .await; + INDEX.wait_task(response.uid()).await.succeeded(); + } + &INDEX +} + static SCORE_DOCUMENTS: Lazy = Lazy::new(|| { json!([ { @@ -135,6 +160,29 @@ static NESTED_DOCUMENTS: Lazy = Lazy::new(|| { ]) }); +pub async fn shared_index_with_nested_documents() -> &'static Index<'static> { + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + let uuid = Uuid::new_v4(); + let index = server.index(uuid.to_string()); + index + }); + let index = Lazy::get(&INDEX); + // That means the lazy has never been initialized, we need to create the index and index the documents + if index.is_none() { + let documents = NESTED_DOCUMENTS.clone(); + let (response, _code) = INDEX.add_documents(documents, None).await; + INDEX.wait_task(response.uid()).await.succeeded(); + let (response, _code) = INDEX + .update_settings( + json!({"filterableAttributes": ["father", "doggos"], "sortableAttributes": ["doggos"]}), + ) + .await; + INDEX.wait_task(response.uid()).await.succeeded(); + } + &INDEX +} + static FRUITS_DOCUMENTS: Lazy = Lazy::new(|| { json!([ { @@ -210,13 +258,7 @@ static VECTOR_DOCUMENTS: Lazy = Lazy::new(|| { #[actix_rt::test] async fn simple_placeholder_search() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -224,11 +266,7 @@ async fn simple_placeholder_search() { }) .await; - let index = server.index("nested"); - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_nested_documents().await; index .search(json!({}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -239,13 +277,7 @@ async fn simple_placeholder_search() { #[actix_rt::test] async fn simple_search() { - let server = Server::new().await; - let index = server.index("test"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"q": "glass"}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -253,11 +285,7 @@ async fn simple_search() { }) .await; - let index = server.index("nested"); - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_nested_documents().await; index .search(json!({"q": "pésti"}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -289,13 +317,7 @@ async fn phrase_search_with_stop_word() { #[actix_rt::test] async fn negative_phrase_search() { - let server = Server::new().await; - let index = server.index("test"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"q": "-\"train your dragon\"" }), |response, code| { assert_eq!(code, 200, "{}", response); @@ -311,13 +333,7 @@ async fn negative_phrase_search() { #[actix_rt::test] async fn negative_word_search() { - let server = Server::new().await; - let index = server.index("test"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"q": "-escape" }), |response, code| { assert_eq!(code, 200, "{}", response); @@ -342,13 +358,7 @@ async fn negative_word_search() { #[actix_rt::test] async fn non_negative_search() { - let server = Server::new().await; - let index = server.index("test"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"q": "- escape" }), |response, code| { assert_eq!(code, 200, "{}", response); @@ -440,13 +450,7 @@ async fn test_thai_language() { #[actix_rt::test] async fn search_multiple_params() { - let server = Server::new().await; - let index = server.index("test"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search( json!({ @@ -463,11 +467,7 @@ async fn search_multiple_params() { ) .await; - let index = server.index("nested"); - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_nested_documents().await; index .search( json!({ @@ -553,15 +553,7 @@ async fn search_with_filter_string_notation() { #[actix_rt::test] async fn search_with_filter_array_notation() { - let server = Server::new().await; - let index = server.index("test"); - - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_documents().await; let (response, code) = index .search_post(json!({ "filter": ["title = Gläss"] @@ -607,15 +599,7 @@ async fn search_with_contains_filter() { #[actix_rt::test] async fn search_with_sort_on_numbers() { - let server = Server::new().await; - let index = server.index("test"); - - index.update_settings(json!({"sortableAttributes": ["id"]})).await; - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_documents().await; index .search( json!({ @@ -628,14 +612,7 @@ async fn search_with_sort_on_numbers() { ) .await; - let index = server.index("nested"); - - index.update_settings(json!({"sortableAttributes": ["doggos.age"]})).await; - - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(3).await; - + let index = shared_index_with_nested_documents().await; index .search( json!({ @@ -651,15 +628,7 @@ async fn search_with_sort_on_numbers() { #[actix_rt::test] async fn search_with_sort_on_strings() { - let server = Server::new().await; - let index = server.index("test"); - - index.update_settings(json!({"sortableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_documents().await; index .search( json!({ @@ -672,14 +641,7 @@ async fn search_with_sort_on_strings() { ) .await; - let index = server.index("nested"); - - index.update_settings(json!({"sortableAttributes": ["doggos.name"]})).await; - - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(3).await; - + let index = shared_index_with_nested_documents().await; index .search( json!({ @@ -695,15 +657,7 @@ async fn search_with_sort_on_strings() { #[actix_rt::test] async fn search_with_multiple_sort() { - let server = Server::new().await; - let index = server.index("test"); - - index.update_settings(json!({"sortableAttributes": ["id", "title"]})).await; - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_documents().await; let (response, code) = index .search_post(json!({ "sort": ["id:asc", "title:desc"] @@ -715,15 +669,7 @@ async fn search_with_multiple_sort() { #[actix_rt::test] async fn search_facet_distribution() { - let server = Server::new().await; - let index = server.index("test"); - - index.update_settings(json!({"filterableAttributes": ["title"]})).await; - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; - + let index = shared_index_with_documents().await; index .search( json!({ @@ -738,13 +684,7 @@ async fn search_facet_distribution() { ) .await; - let index = server.index("nested"); - - index.update_settings(json!({"filterableAttributes": ["father", "doggos.name"]})).await; - - let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(3).await; + let index = shared_index_with_nested_documents().await; // TODO: TAMO: fix the test index @@ -771,9 +711,6 @@ async fn search_facet_distribution() { ) .await; - index.update_settings(json!({"filterableAttributes": ["doggos"]})).await; - index.wait_task(4).await; - index .search( json!({ @@ -809,9 +746,6 @@ async fn search_facet_distribution() { ) .await; - index.update_settings(json!({"filterableAttributes": ["doggos.name"]})).await; - index.wait_task(5).await; - index .search( json!({ diff --git a/meilisearch/tests/search/multi.rs b/meilisearch/tests/search/multi.rs index e0158b7c3..89b06c68c 100644 --- a/meilisearch/tests/search/multi.rs +++ b/meilisearch/tests/search/multi.rs @@ -94,7 +94,7 @@ async fn simple_search_single_index() { let (response, code) = server .multi_search(json!({"queries": [ - {"indexUid" : "test", "q": "glass"}, + {"indexUid": "test", "q": "glass"}, {"indexUid": "test", "q": "captain"}, ]})) .await; diff --git a/meilisearch/tests/search/pagination.rs b/meilisearch/tests/search/pagination.rs index ff3b50d04..e889aca6f 100644 --- a/meilisearch/tests/search/pagination.rs +++ b/meilisearch/tests/search/pagination.rs @@ -1,16 +1,11 @@ use crate::common::Server; use crate::json; -use crate::search::DOCUMENTS; + +use super::shared_index_with_documents; #[actix_rt::test] async fn default_search_should_return_estimated_total_hit() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -28,13 +23,7 @@ async fn default_search_should_return_estimated_total_hit() { #[actix_rt::test] async fn simple_search() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"page": 1}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -53,13 +42,7 @@ async fn simple_search() { #[actix_rt::test] async fn page_zero_should_not_return_any_result() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"page": 0}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -73,13 +56,7 @@ async fn page_zero_should_not_return_any_result() { #[actix_rt::test] async fn hits_per_page_1() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"hitsPerPage": 1}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -93,13 +70,7 @@ async fn hits_per_page_1() { #[actix_rt::test] async fn hits_per_page_0_should_not_return_any_result() { - let server = Server::new().await; - let index = server.index("basic"); - - let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - + let index = shared_index_with_documents().await; index .search(json!({"hitsPerPage": 0}), |response, code| { assert_eq!(code, 200, "{}", response); @@ -113,8 +84,8 @@ async fn hits_per_page_0_should_not_return_any_result() { #[actix_rt::test] async fn ensure_placeholder_search_hit_count_valid() { - let server = Server::new().await; - let index = server.index("basic"); + let server = Server::new_shared(); + let index = server.unique_index(); let documents = json!([ { @@ -143,15 +114,15 @@ async fn ensure_placeholder_search_hit_count_valid() { "distinct": 3, } ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task, _code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await.succeeded(); - let (_response, _code) = index + let (response, _code) = index .update_settings( json!({ "rankingRules": ["distinct:asc"], "distinctAttribute": "distinct"}), ) .await; - index.wait_task(1).await; + index.wait_task(response.uid()).await.succeeded(); for page in 0..=4 { index diff --git a/meilisearch/tests/search/restrict_searchable.rs b/meilisearch/tests/search/restrict_searchable.rs index f52efa1f4..ca659c518 100644 --- a/meilisearch/tests/search/restrict_searchable.rs +++ b/meilisearch/tests/search/restrict_searchable.rs @@ -8,8 +8,8 @@ use crate::json; async fn index_with_documents<'a>(server: &'a Server, documents: &Value) -> Index<'a> { let index = server.index("test"); - index.add_documents(documents.clone(), None).await; - index.wait_task(0).await; + let (task, _code) = index.add_documents(documents.clone(), None).await; + index.wait_task(task.uid()).await.succeeded(); index } From ed795bc837cff061c491c491584c9d7c84bf8903 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 18:33:04 +0200 Subject: [PATCH 06/15] fmt --- meilisearch/tests/search/pagination.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meilisearch/tests/search/pagination.rs b/meilisearch/tests/search/pagination.rs index e889aca6f..ff601bd5b 100644 --- a/meilisearch/tests/search/pagination.rs +++ b/meilisearch/tests/search/pagination.rs @@ -1,8 +1,7 @@ +use super::shared_index_with_documents; use crate::common::Server; use crate::json; -use super::shared_index_with_documents; - #[actix_rt::test] async fn default_search_should_return_estimated_total_hit() { let index = shared_index_with_documents().await; From d262b1df327e80579985d46bf5696305fb2ee9d7 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 10:27:57 +0200 Subject: [PATCH 07/15] craft an API over the Shared Server and Shared index to avoid hard to debug mistakes --- meilisearch/tests/common/index.rs | 257 ++++++++++++++---------- meilisearch/tests/common/mod.rs | 270 +++++++++++++++++++++++++- meilisearch/tests/common/server.rs | 238 +++++++++++++++-------- meilisearch/tests/documents/errors.rs | 102 ++++------ meilisearch/tests/index/errors.rs | 41 ++-- meilisearch/tests/search/errors.rs | 11 +- meilisearch/tests/search/mod.rs | 241 +---------------------- meilisearch/tests/settings/errors.rs | 24 +-- milli/src/search/facet/filter.rs | 30 ++- 9 files changed, 668 insertions(+), 546 deletions(-) diff --git a/meilisearch/tests/common/index.rs b/meilisearch/tests/common/index.rs index 045f8673c..381bd1cb4 100644 --- a/meilisearch/tests/common/index.rs +++ b/meilisearch/tests/common/index.rs @@ -1,4 +1,5 @@ use std::fmt::Write; +use std::marker::PhantomData; use std::panic::{catch_unwind, resume_unwind, UnwindSafe}; use std::time::Duration; @@ -9,19 +10,24 @@ use urlencoding::encode as urlencode; use super::encoder::Encoder; use super::service::Service; use super::Value; +use super::{Owned, Shared}; use crate::json; -pub struct Index<'a> { +pub struct Index<'a, State = Owned> { pub uid: String, pub service: &'a Service, - pub encoder: Encoder, + pub(super) encoder: Encoder, + pub(super) marker: PhantomData, } -#[allow(dead_code)] -impl Index<'_> { - pub async fn get(&self) -> (Value, StatusCode) { - let url = format!("/indexes/{}", urlencode(self.uid.as_ref())); - self.service.get(url).await +impl<'a> Index<'a, Owned> { + pub fn to_shared(&self) -> Index<'a, Shared> { + Index { + uid: self.uid.clone(), + service: self.service, + encoder: self.encoder, + marker: PhantomData, + } } pub async fn load_test_set(&self) -> u64 { @@ -57,11 +63,7 @@ impl Index<'_> { } pub async fn create(&self, primary_key: Option<&str>) -> (Value, StatusCode) { - let body = json!({ - "uid": self.uid, - "primaryKey": primary_key, - }); - self.service.post_encoded("/indexes", body, self.encoder).await + self._create(primary_key).await } pub async fn update_raw(&self, body: Value) -> (Value, StatusCode) { @@ -88,13 +90,7 @@ impl Index<'_> { documents: Value, primary_key: Option<&str>, ) -> (Value, StatusCode) { - let url = match primary_key { - Some(key) => { - format!("/indexes/{}/documents?primaryKey={}", urlencode(self.uid.as_ref()), key) - } - None => format!("/indexes/{}/documents", urlencode(self.uid.as_ref())), - }; - self.service.post_encoded(url, documents, self.encoder).await + self._add_documents(documents, primary_key).await } pub async fn raw_add_documents( @@ -136,80 +132,11 @@ impl Index<'_> { } } - pub async fn wait_task(&self, update_id: u64) -> Value { - // try several times to get status, or panic to not wait forever - let url = format!("/tasks/{}", update_id); - for _ in 0..100 { - let (response, status_code) = self.service.get(&url).await; - assert_eq!(200, status_code, "response: {}", response); - - if response["status"] == "succeeded" || response["status"] == "failed" { - return response; - } - - // wait 0.5 second. - sleep(Duration::from_millis(500)).await; - } - panic!("Timeout waiting for update id"); - } - - pub async fn get_task(&self, update_id: u64) -> (Value, StatusCode) { - let url = format!("/tasks/{}", update_id); - self.service.get(url).await - } - pub async fn list_tasks(&self) -> (Value, StatusCode) { let url = format!("/tasks?indexUids={}", self.uid); self.service.get(url).await } - pub async fn filtered_tasks( - &self, - types: &[&str], - statuses: &[&str], - canceled_by: &[&str], - ) -> (Value, StatusCode) { - let mut url = format!("/tasks?indexUids={}", self.uid); - if !types.is_empty() { - let _ = write!(url, "&types={}", types.join(",")); - } - if !statuses.is_empty() { - let _ = write!(url, "&statuses={}", statuses.join(",")); - } - if !canceled_by.is_empty() { - let _ = write!(url, "&canceledBy={}", canceled_by.join(",")); - } - self.service.get(url).await - } - - pub async fn get_document(&self, id: u64, options: Option) -> (Value, StatusCode) { - let mut url = format!("/indexes/{}/documents/{}", urlencode(self.uid.as_ref()), id); - if let Some(options) = options { - write!(url, "{}", yaup::to_string(&options).unwrap()).unwrap(); - } - self.service.get(url).await - } - - pub async fn get_document_by_filter(&self, payload: Value) -> (Value, StatusCode) { - let url = format!("/indexes/{}/documents/fetch", urlencode(self.uid.as_ref())); - self.service.post(url, payload).await - } - - pub async fn get_all_documents_raw(&self, options: &str) -> (Value, StatusCode) { - let url = format!("/indexes/{}/documents{}", urlencode(self.uid.as_ref()), options); - self.service.get(url).await - } - - pub async fn get_all_documents(&self, options: GetAllDocumentsOptions) -> (Value, StatusCode) { - let url = format!( - "/indexes/{}/documents{}", - urlencode(self.uid.as_ref()), - yaup::to_string(&options).unwrap() - ); - - self.service.get(url).await - } - pub async fn delete_document(&self, id: u64) -> (Value, StatusCode) { let url = format!("/indexes/{}/documents/{}", urlencode(self.uid.as_ref()), id); self.service.delete(url).await @@ -237,14 +164,8 @@ impl Index<'_> { self.service.post_encoded(url, body, self.encoder).await } - pub async fn settings(&self) -> (Value, StatusCode) { - let url = format!("/indexes/{}/settings", urlencode(self.uid.as_ref())); - self.service.get(url).await - } - pub async fn update_settings(&self, settings: Value) -> (Value, StatusCode) { - let url = format!("/indexes/{}/settings", urlencode(self.uid.as_ref())); - self.service.patch_encoded(url, settings, self.encoder).await + self._update_settings(settings).await } pub async fn update_settings_displayed_attributes( @@ -327,6 +248,146 @@ impl Index<'_> { self.service.delete(url).await } + pub async fn update_distinct_attribute(&self, value: Value) -> (Value, StatusCode) { + let url = + format!("/indexes/{}/settings/{}", urlencode(self.uid.as_ref()), "distinct-attribute"); + self.service.put_encoded(url, value, self.encoder).await + } +} + +impl<'a> Index<'a, Shared> { + /// You cannot modify the content of a shared index, thus the delete_document_by_filter call + /// must fail. If the task successfully enqueue itself, we'll wait for the task to finishes, + /// and if it succeed the function will panic. + pub async fn delete_document_by_filter_fail(&self, body: Value) -> (Value, StatusCode) { + let (mut task, code) = self._delete_document_by_filter(body).await; + if code.is_success() { + task = self.wait_task(task.uid()).await; + if task.is_success() { + panic!( + "`delete_document_by_filter_fail` succeeded: {}", + serde_json::to_string_pretty(&task).unwrap() + ); + } + } + (task, code) + } +} + +#[allow(dead_code)] +impl Index<'_, State> { + pub async fn get(&self) -> (Value, StatusCode) { + let url = format!("/indexes/{}", urlencode(self.uid.as_ref())); + self.service.get(url).await + } + + /// add_documents is not allowed on shared index but we need to use it to initialize + /// a bunch of very common indexes in `common/mod.rs`. + pub(super) async fn _add_documents( + &self, + documents: Value, + primary_key: Option<&str>, + ) -> (Value, StatusCode) { + let url = match primary_key { + Some(key) => { + format!("/indexes/{}/documents?primaryKey={}", urlencode(self.uid.as_ref()), key) + } + None => format!("/indexes/{}/documents", urlencode(self.uid.as_ref())), + }; + self.service.post_encoded(url, documents, self.encoder).await + } + + pub(super) async fn _update_settings(&self, settings: Value) -> (Value, StatusCode) { + let url = format!("/indexes/{}/settings", urlencode(self.uid.as_ref())); + self.service.patch_encoded(url, settings, self.encoder).await + } + + pub(super) async fn _delete_document_by_filter(&self, body: Value) -> (Value, StatusCode) { + let url = format!("/indexes/{}/documents/delete", urlencode(self.uid.as_ref())); + self.service.post_encoded(url, body, self.encoder).await + } + + pub(super) async fn _create(&self, primary_key: Option<&str>) -> (Value, StatusCode) { + let body = json!({ + "uid": self.uid, + "primaryKey": primary_key, + }); + self.service.post_encoded("/indexes", body, self.encoder).await + } + pub async fn wait_task(&self, update_id: u64) -> Value { + // try several times to get status, or panic to not wait forever + let url = format!("/tasks/{}", update_id); + for _ in 0..100 { + let (response, status_code) = self.service.get(&url).await; + assert_eq!(200, status_code, "response: {}", response); + + if response["status"] == "succeeded" || response["status"] == "failed" { + return response; + } + + // wait 0.5 second. + sleep(Duration::from_millis(500)).await; + } + panic!("Timeout waiting for update id"); + } + + pub async fn get_task(&self, update_id: u64) -> (Value, StatusCode) { + let url = format!("/tasks/{}", update_id); + self.service.get(url).await + } + + pub async fn filtered_tasks( + &self, + types: &[&str], + statuses: &[&str], + canceled_by: &[&str], + ) -> (Value, StatusCode) { + let mut url = format!("/tasks?indexUids={}", self.uid); + if !types.is_empty() { + let _ = write!(url, "&types={}", types.join(",")); + } + if !statuses.is_empty() { + let _ = write!(url, "&statuses={}", statuses.join(",")); + } + if !canceled_by.is_empty() { + let _ = write!(url, "&canceledBy={}", canceled_by.join(",")); + } + self.service.get(url).await + } + + pub async fn get_document(&self, id: u64, options: Option) -> (Value, StatusCode) { + let mut url = format!("/indexes/{}/documents/{}", urlencode(self.uid.as_ref()), id); + if let Some(options) = options { + write!(url, "{}", yaup::to_string(&options).unwrap()).unwrap(); + } + self.service.get(url).await + } + + pub async fn get_document_by_filter(&self, payload: Value) -> (Value, StatusCode) { + let url = format!("/indexes/{}/documents/fetch", urlencode(self.uid.as_ref())); + self.service.post(url, payload).await + } + + pub async fn get_all_documents_raw(&self, options: &str) -> (Value, StatusCode) { + let url = format!("/indexes/{}/documents{}", urlencode(self.uid.as_ref()), options); + self.service.get(url).await + } + + pub async fn get_all_documents(&self, options: GetAllDocumentsOptions) -> (Value, StatusCode) { + let url = format!( + "/indexes/{}/documents{}", + urlencode(self.uid.as_ref()), + yaup::to_string(&options).unwrap() + ); + + self.service.get(url).await + } + + pub async fn settings(&self) -> (Value, StatusCode) { + let url = format!("/indexes/{}/settings", urlencode(self.uid.as_ref())); + self.service.get(url).await + } + pub async fn stats(&self) -> (Value, StatusCode) { let url = format!("/indexes/{}/stats", urlencode(self.uid.as_ref())); self.service.get(url).await @@ -411,12 +472,6 @@ impl Index<'_> { self.service.post_encoded(url, query, self.encoder).await } - pub async fn update_distinct_attribute(&self, value: Value) -> (Value, StatusCode) { - let url = - format!("/indexes/{}/settings/{}", urlencode(self.uid.as_ref()), "distinct-attribute"); - self.service.put_encoded(url, value, self.encoder).await - } - pub async fn get_distinct_attribute(&self) -> (Value, StatusCode) { let url = format!("/indexes/{}/settings/{}", urlencode(self.uid.as_ref()), "distinct-attribute"); diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index 0c4e8e25c..58f531b6d 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -8,10 +8,16 @@ use std::fmt::{self, Display}; #[allow(unused)] pub use index::GetAllDocumentsOptions; use meili_snap::json_string; +use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; #[allow(unused)] pub use server::{default_settings, Server}; +use crate::common::index::Index; + +pub enum Shared {} +pub enum Owned {} + #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] pub struct Value(pub serde_json::Value); @@ -27,10 +33,20 @@ impl Value { } } + /// Return `true` if the `status` field is set to `succeeded`. + /// Panic if the `status` field doesn't exists. + #[track_caller] + pub fn is_success(&self) -> bool { + if !self["status"].is_string() { + panic!("Called `is_success` on {}", serde_json::to_string_pretty(&self.0).unwrap()); + } + self["status"] == serde_json::Value::String(String::from("succeeded")) + } + // Panic if the json doesn't contain the `status` field set to "succeeded" #[track_caller] pub fn succeeded(&self) -> &Self { - if self["status"] != serde_json::Value::String(String::from("succeeded")) { + if !self.is_success() { panic!("Called succeeded on {}", serde_json::to_string_pretty(&self.0).unwrap()); } self @@ -122,3 +138,255 @@ macro_rules! test_post_get_search { .map_err(|e| panic!("panic in post route: {:?}", e.downcast_ref::<&str>().unwrap())); }; } + +pub async fn shared_does_not_exists_index() -> &'static Index<'static, Shared> { + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + server._index("DOES_NOT_EXISTS").to_shared() + }); + &INDEX +} + +pub async fn shared_empty_index() -> &'static Index<'static, Shared> { + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + server._index("EMPTY_INDEX").to_shared() + }); + let index = Lazy::get(&INDEX); + // That means the lazy has never been initialized, we need to create the index and index the documents + if index.is_none() { + let (response, _code) = INDEX._create(None).await; + INDEX.wait_task(response.uid()).await.succeeded(); + } + &INDEX +} + +pub static DOCUMENTS: Lazy = Lazy::new(|| { + json!([ + { + "title": "Shazam!", + "id": "287947", + "_vectors": { "manual": [1, 2, 3]}, + }, + { + "title": "Captain Marvel", + "id": "299537", + "_vectors": { "manual": [1, 2, 54] }, + }, + { + "title": "Escape Room", + "id": "522681", + "_vectors": { "manual": [10, -23, 32] }, + }, + { + "title": "How to Train Your Dragon: The Hidden World", + "id": "166428", + "_vectors": { "manual": [-100, 231, 32] }, + }, + { + "title": "Gläss", + "id": "450465", + "_vectors": { "manual": [-100, 340, 90] }, + } + ]) +}); + +pub async fn shared_index_with_documents() -> &'static Index<'static, Shared> { + // We cannot store a `Shared` index directly because we need to do more initialization work later on + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + server._index("SHARED_DOCUMENTS").to_shared() + }); + let index = Lazy::get(&INDEX); + // That means the lazy has never been initialized, we need to create the index and index the documents + if index.is_none() { + let documents = DOCUMENTS.clone(); + let (response, _code) = INDEX._add_documents(documents, None).await; + INDEX.wait_task(response.uid()).await.succeeded(); + let (response, _code) = INDEX + ._update_settings( + json!({"filterableAttributes": ["id", "title"], "sortableAttributes": ["id", "title"]}), + ) + .await; + INDEX.wait_task(response.uid()).await.succeeded(); + } + &INDEX +} + +pub static SCORE_DOCUMENTS: Lazy = Lazy::new(|| { + json!([ + { + "title": "Batman the dark knight returns: Part 1", + "id": "A", + }, + { + "title": "Batman the dark knight returns: Part 2", + "id": "B", + }, + { + "title": "Batman Returns", + "id": "C", + }, + { + "title": "Batman", + "id": "D", + }, + { + "title": "Badman", + "id": "E", + } + ]) +}); + +pub static NESTED_DOCUMENTS: Lazy = Lazy::new(|| { + json!([ + { + "id": 852, + "father": "jean", + "mother": "michelle", + "doggos": [ + { + "name": "bobby", + "age": 2, + }, + { + "name": "buddy", + "age": 4, + }, + ], + "cattos": "pésti", + "_vectors": { "manual": [1, 2, 3]}, + }, + { + "id": 654, + "father": "pierre", + "mother": "sabine", + "doggos": [ + { + "name": "gros bill", + "age": 8, + }, + ], + "cattos": ["simba", "pestiféré"], + "_vectors": { "manual": [1, 2, 54] }, + }, + { + "id": 750, + "father": "romain", + "mother": "michelle", + "cattos": ["enigma"], + "_vectors": { "manual": [10, 23, 32] }, + }, + { + "id": 951, + "father": "jean-baptiste", + "mother": "sophie", + "doggos": [ + { + "name": "turbo", + "age": 5, + }, + { + "name": "fast", + "age": 6, + }, + ], + "cattos": ["moumoute", "gomez"], + "_vectors": { "manual": [10, 23, 32] }, + }, + ]) +}); + +pub async fn shared_index_with_nested_documents() -> &'static Index<'static, Shared> { + static INDEX: Lazy> = Lazy::new(|| { + let server = Server::new_shared(); + server._index("SHARED_NESTED_DOCUMENTS").to_shared() + }); + let index = Lazy::get(&INDEX); + // That means the lazy has never been initialized, we need to create the index and index the documents + if index.is_none() { + let documents = NESTED_DOCUMENTS.clone(); + let (response, _code) = INDEX._add_documents(documents, None).await; + INDEX.wait_task(response.uid()).await.succeeded(); + let (response, _code) = INDEX + ._update_settings( + json!({"filterableAttributes": ["father", "doggos"], "sortableAttributes": ["doggos"]}), + ) + .await; + INDEX.wait_task(response.uid()).await.succeeded(); + } + &INDEX +} + +pub static FRUITS_DOCUMENTS: Lazy = Lazy::new(|| { + json!([ + { + "name": "Exclusive sale: green apple", + "id": "green-apple-boosted", + "BOOST": true + }, + { + "name": "Pear", + "id": "pear", + }, + { + "name": "Red apple gala", + "id": "red-apple-gala", + }, + { + "name": "Exclusive sale: Red Tomato", + "id": "red-tomatoes-boosted", + "BOOST": true + }, + { + "name": "Exclusive sale: Red delicious apple", + "id": "red-delicious-boosted", + "BOOST": true, + } + ]) +}); + +pub static VECTOR_DOCUMENTS: Lazy = Lazy::new(|| { + json!([ + { + "id": "A", + "description": "the dog barks at the cat", + "_vectors": { + // dimensions [canine, feline, young] + "animal": [0.9, 0.8, 0.05], + // dimensions [negative/positive, energy] + "sentiment": [-0.1, 0.55] + } + }, + { + "id": "B", + "description": "the kitten scratched the beagle", + "_vectors": { + // dimensions [canine, feline, young] + "animal": [0.8, 0.9, 0.5], + // dimensions [negative/positive, energy] + "sentiment": [-0.2, 0.65] + } + }, + { + "id": "C", + "description": "the dog had to stay alone today", + "_vectors": { + // dimensions [canine, feline, young] + "animal": [0.85, 0.02, 0.1], + // dimensions [negative/positive, energy] + "sentiment": [-1.0, 0.1] + } + }, + { + "id": "D", + "description": "the little boy pets the puppy", + "_vectors": { + // dimensions [canine, feline, young] + "animal": [0.8, 0.09, 0.8], + // dimensions [negative/positive, energy] + "sentiment": [0.8, 0.3] + } + }, + ]) +}); diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index 28ddbe754..e69b3eb6e 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] +use std::marker::PhantomData; use std::path::Path; use std::str::FromStr as _; use std::time::Duration; @@ -20,41 +21,22 @@ use uuid::Uuid; use super::index::Index; use super::service::Service; +use super::{Owned, Shared}; use crate::common::encoder::Encoder; use crate::common::Value; use crate::json; -pub struct Server { +pub struct Server { pub service: Service, // hold ownership to the tempdir while we use the server instance. _dir: Option, + _marker: PhantomData, } pub static TEST_TEMP_DIR: Lazy = Lazy::new(|| TempDir::new().unwrap()); -pub static TEST_SHARED_INSTANCE: Lazy = Lazy::new(Server::init_new_shared_instance); - -impl Server { - fn init_new_shared_instance() -> Self { - let dir = TempDir::new().unwrap(); - - if cfg!(windows) { - std::env::set_var("TMP", TEST_TEMP_DIR.path()); - } else { - std::env::set_var("TMPDIR", TEST_TEMP_DIR.path()); - } - - let options = default_settings(dir.path()); - - let (index_scheduler, auth) = setup_meilisearch(&options).unwrap(); - let service = Service { index_scheduler, auth, options, api_key: None }; - - Server { service, _dir: Some(dir) } - } - - pub fn new_shared() -> &'static Self { - &TEST_SHARED_INSTANCE - } +pub static TEST_SHARED_INSTANCE: Lazy> = Lazy::new(Server::init_new_shared_instance); +impl Server { pub async fn new() -> Self { let dir = TempDir::new().unwrap(); @@ -69,7 +51,7 @@ impl Server { let (index_scheduler, auth) = setup_meilisearch(&options).unwrap(); let service = Service { index_scheduler, auth, options, api_key: None }; - Server { service, _dir: Some(dir) } + Server { service, _dir: Some(dir), _marker: PhantomData } } pub async fn new_auth_with_options(mut options: Opt, dir: TempDir) -> Self { @@ -84,7 +66,7 @@ impl Server { let (index_scheduler, auth) = setup_meilisearch(&options).unwrap(); let service = Service { index_scheduler, auth, options, api_key: None }; - Server { service, _dir: Some(dir) } + Server { service, _dir: Some(dir), _marker: PhantomData } } pub async fn new_auth() -> Self { @@ -97,9 +79,139 @@ impl Server { let (index_scheduler, auth) = setup_meilisearch(&options)?; let service = Service { index_scheduler, auth, options, api_key: None }; - Ok(Server { service, _dir: None }) + Ok(Server { service, _dir: None, _marker: PhantomData }) } + /// Returns a view to an index. There is no guarantee that the index exists. + pub fn index(&self, uid: impl AsRef) -> Index<'_> { + self.index_with_encoder(uid, Encoder::Plain) + } + + pub async fn create_index(&self, body: Value) -> (Value, StatusCode) { + self.service.post("/indexes", body).await + } + + pub fn index_with_encoder(&self, uid: impl AsRef, encoder: Encoder) -> Index<'_> { + Index { + uid: uid.as_ref().to_string(), + service: &self.service, + encoder, + marker: PhantomData, + } + } + + pub async fn list_indexes( + &self, + offset: Option, + limit: Option, + ) -> (Value, StatusCode) { + let (offset, limit) = ( + offset.map(|offset| format!("offset={offset}")), + limit.map(|limit| format!("limit={limit}")), + ); + let query_parameter = offset + .as_ref() + .zip(limit.as_ref()) + .map(|(offset, limit)| format!("{offset}&{limit}")) + .or_else(|| offset.xor(limit)); + if let Some(query_parameter) = query_parameter { + self.service.get(format!("/indexes?{query_parameter}")).await + } else { + self.service.get("/indexes").await + } + } + + pub async fn stats(&self) -> (Value, StatusCode) { + self.service.get("/stats").await + } + + pub async fn tasks(&self) -> (Value, StatusCode) { + self.service.get("/tasks").await + } + + pub async fn set_features(&self, value: Value) -> (Value, StatusCode) { + self.service.patch("/experimental-features", value).await + } + + pub async fn get_metrics(&self) -> (Value, StatusCode) { + self.service.get("/metrics").await + } +} + +impl Server { + fn init_new_shared_instance() -> Server { + let dir = TempDir::new().unwrap(); + + if cfg!(windows) { + std::env::set_var("TMP", TEST_TEMP_DIR.path()); + } else { + std::env::set_var("TMPDIR", TEST_TEMP_DIR.path()); + } + + let options = default_settings(dir.path()); + + let (index_scheduler, auth) = setup_meilisearch(&options).unwrap(); + let service = Service { index_scheduler, auth, options, api_key: None }; + + Server { service, _dir: Some(dir), _marker: PhantomData } + } + + pub fn new_shared() -> &'static Server { + &TEST_SHARED_INSTANCE + } + + /// You shouldn't access random indexes on a shared instance thus this method + /// must fail. + pub async fn get_index_fail(&self, uid: impl AsRef) -> (Value, StatusCode) { + let url = format!("/indexes/{}", urlencoding::encode(uid.as_ref())); + let (value, code) = self.service.get(url).await; + if code.is_success() { + panic!("`get_index_fail` succeeded with uid: {}", uid.as_ref()); + } + (value, code) + } + + pub async fn delete_index_fail(&self, uid: impl AsRef) -> (Value, StatusCode) { + let url = format!("/indexes/{}", urlencoding::encode(uid.as_ref())); + let (value, code) = self.service.delete(url).await; + if code.is_success() { + panic!("`delete_index_fail` succeeded with uid: {}", uid.as_ref()); + } + (value, code) + } + + pub async fn update_raw_index_fail( + &self, + uid: impl AsRef, + body: Value, + ) -> (Value, StatusCode) { + let url = format!("/indexes/{}", urlencoding::encode(uid.as_ref())); + let (value, code) = self.service.patch_encoded(url, body, Encoder::Plain).await; + if code.is_success() { + panic!("`update_raw_index_fail` succeeded with uid: {}", uid.as_ref()); + } + (value, code) + } + + /// Since this call updates the state of the instance, it must fail. + /// If it doesn't fail, the test will panic to help you debug what + /// is going on. + pub async fn create_index_fail(&self, body: Value) -> (Value, StatusCode) { + let (mut task, code) = self._create_index(body).await; + if code.is_success() { + task = self.wait_task(task.uid()).await; + if task.is_success() { + panic!( + "`create_index_fail` succeeded: {}", + serde_json::to_string_pretty(&task).unwrap() + ); + } + } + (task, code) + } +} + +impl Server { pub async fn init_web_app( &self, ) -> impl actix_web::dev::Service< @@ -131,25 +243,30 @@ impl Server { .await } + pub(super) fn _index(&self, uid: impl AsRef) -> Index<'_> { + Index { + uid: uid.as_ref().to_string(), + service: &self.service, + encoder: Encoder::Plain, + marker: PhantomData, + } + } + /// Returns a view to an index. There is no guarantee that the index exists. pub fn unique_index(&self) -> Index<'_> { let uuid = Uuid::new_v4(); - self.index_with_encoder(uuid.to_string(), Encoder::Plain) + Index { + uid: uuid.to_string(), + service: &self.service, + encoder: Encoder::Plain, + marker: PhantomData, + } } - /// Returns a view to an index. There is no guarantee that the index exists. - pub fn index(&self, uid: impl AsRef) -> Index<'_> { - self.index_with_encoder(uid, Encoder::Plain) - } - - pub async fn create_index(&self, body: Value) -> (Value, StatusCode) { + pub(super) async fn _create_index(&self, body: Value) -> (Value, StatusCode) { self.service.post("/indexes", body).await } - pub fn index_with_encoder(&self, uid: impl AsRef, encoder: Encoder) -> Index<'_> { - Index { uid: uid.as_ref().to_string(), service: &self.service, encoder } - } - pub async fn multi_search(&self, queries: Value) -> (Value, StatusCode) { self.service.post("/multi-search", queries).await } @@ -158,45 +275,12 @@ impl Server { self.service.get(format!("/indexes{parameters}")).await } - pub async fn list_indexes( - &self, - offset: Option, - limit: Option, - ) -> (Value, StatusCode) { - let (offset, limit) = ( - offset.map(|offset| format!("offset={offset}")), - limit.map(|limit| format!("limit={limit}")), - ); - let query_parameter = offset - .as_ref() - .zip(limit.as_ref()) - .map(|(offset, limit)| format!("{offset}&{limit}")) - .or_else(|| offset.xor(limit)); - if let Some(query_parameter) = query_parameter { - self.service.get(format!("/indexes?{query_parameter}")).await - } else { - self.service.get("/indexes").await - } - } - - pub async fn version(&self) -> (Value, StatusCode) { - self.service.get("/version").await - } - - pub async fn stats(&self) -> (Value, StatusCode) { - self.service.get("/stats").await - } - - pub async fn tasks(&self) -> (Value, StatusCode) { - self.service.get("/tasks").await - } - pub async fn tasks_filter(&self, filter: &str) -> (Value, StatusCode) { self.service.get(format!("/tasks?{}", filter)).await } - pub async fn get_dump_status(&self, uid: &str) -> (Value, StatusCode) { - self.service.get(format!("/dumps/{}/status", uid)).await + pub async fn version(&self) -> (Value, StatusCode) { + self.service.get("/version").await } pub async fn create_dump(&self) -> (Value, StatusCode) { @@ -244,14 +328,6 @@ impl Server { pub async fn get_features(&self) -> (Value, StatusCode) { self.service.get("/experimental-features").await } - - pub async fn set_features(&self, value: Value) -> (Value, StatusCode) { - self.service.patch("/experimental-features", value).await - } - - pub async fn get_metrics(&self) -> (Value, StatusCode) { - self.service.get("/metrics").await - } } pub fn default_settings(dir: impl AsRef) -> Opt { diff --git a/meilisearch/tests/documents/errors.rs b/meilisearch/tests/documents/errors.rs index 2d2c2bd6b..2c5f2a965 100644 --- a/meilisearch/tests/documents/errors.rs +++ b/meilisearch/tests/documents/errors.rs @@ -1,14 +1,15 @@ use meili_snap::*; use urlencoding::encode; -use crate::common::Server; +use crate::common::{ + shared_does_not_exists_index, shared_empty_index, shared_index_with_documents, Server, +}; use crate::json; #[actix_rt::test] async fn get_all_documents_bad_offset() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.get_all_documents_raw("?offset").await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -46,8 +47,7 @@ async fn get_all_documents_bad_offset() { #[actix_rt::test] async fn get_all_documents_bad_limit() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.get_all_documents_raw("?limit").await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -84,17 +84,13 @@ async fn get_all_documents_bad_limit() { #[actix_rt::test] async fn get_all_documents_bad_filter() { - let server = Server::new_shared(); - let index = server.index("test"); + let index = shared_does_not_exists_index().await; - // Since the filter can't be parsed automatically by deserr, we have the wrong error message - // if the index does not exist: we could expect to get an error message about the invalid filter before - // the existence of the index is checked, but it is not the case. let (response, code) = index.get_all_documents_raw("?filter").await; snapshot!(code, @"404 Not Found"); snapshot!(json_string!(response), @r###" { - "message": "Index `test` not found.", + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -105,7 +101,7 @@ async fn get_all_documents_bad_filter() { snapshot!(code, @"404 Not Found"); snapshot!(json_string!(response), @r###" { - "message": "Index `test` not found.", + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -116,15 +112,14 @@ async fn get_all_documents_bad_filter() { snapshot!(code, @"404 Not Found"); snapshot!(json_string!(response), @r###" { - "message": "Index `test` not found.", + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" } "###); - let (response, _code) = index.create(None).await; - server.wait_task(response.uid()).await.succeeded(); + let index = shared_empty_index().await; let (response, code) = index.get_all_documents_raw("?filter").await; snapshot!(code, @"200 OK"); @@ -163,8 +158,7 @@ async fn get_all_documents_bad_filter() { #[actix_rt::test] async fn delete_documents_batch() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.delete_batch_raw(json!("doggo")).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -180,8 +174,7 @@ async fn delete_documents_batch() { #[actix_rt::test] async fn replace_documents_missing_payload() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_add_documents("", vec![("Content-Type", "application/json")], "").await; snapshot!(code, @"400 Bad Request"); @@ -222,8 +215,7 @@ async fn replace_documents_missing_payload() { #[actix_rt::test] async fn update_documents_missing_payload() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_update_documents("", Some("application/json"), "").await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -261,8 +253,7 @@ async fn update_documents_missing_payload() { #[actix_rt::test] async fn replace_documents_missing_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_add_documents("", Vec::new(), "").await; snapshot!(code, @"415 Unsupported Media Type"); snapshot!(json_string!(response), @r###" @@ -290,8 +281,7 @@ async fn replace_documents_missing_content_type() { #[actix_rt::test] async fn update_documents_missing_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_update_documents("", None, "").await; snapshot!(code, @"415 Unsupported Media Type"); snapshot!(json_string!(response), @r###" @@ -319,8 +309,7 @@ async fn update_documents_missing_content_type() { #[actix_rt::test] async fn replace_documents_bad_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_add_documents("", vec![("Content-Type", "doggo")], "").await; snapshot!(code, @"415 Unsupported Media Type"); snapshot!(json_string!(response), @r###" @@ -336,8 +325,7 @@ async fn replace_documents_bad_content_type() { #[actix_rt::test] async fn update_documents_bad_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_update_documents("", Some("doggo"), "").await; snapshot!(code, @"415 Unsupported Media Type"); snapshot!(json_string!(response), @r###" @@ -353,8 +341,7 @@ async fn update_documents_bad_content_type() { #[actix_rt::test] async fn replace_documents_bad_csv_delimiter() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index .raw_add_documents("", vec![("Content-Type", "application/json")], "?csvDelimiter") .await; @@ -402,8 +389,7 @@ async fn replace_documents_bad_csv_delimiter() { #[actix_rt::test] async fn update_documents_bad_csv_delimiter() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_update_documents("", Some("application/json"), "?csvDelimiter").await; snapshot!(code, @"400 Bad Request"); @@ -449,8 +435,7 @@ async fn update_documents_bad_csv_delimiter() { #[actix_rt::test] async fn replace_documents_csv_delimiter_with_bad_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index .raw_add_documents("", vec![("Content-Type", "application/json")], "?csvDelimiter=a") .await; @@ -481,8 +466,7 @@ async fn replace_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn update_documents_csv_delimiter_with_bad_content_type() { let server = Server::new_shared(); - let index = server.index("test"); - + let index = server.unique_index(); let (response, code) = index.raw_update_documents("", Some("application/json"), "?csvDelimiter=a").await; snapshot!(code, @"415 Unsupported Media Type"); @@ -511,9 +495,8 @@ async fn update_documents_csv_delimiter_with_bad_content_type() { #[actix_rt::test] async fn delete_document_by_filter() { let server = Server::new_shared(); - let index = server.index("tests-documents-errors-delete_document_by_filter"); + let index = server.unique_index(); - // send a bad payload type let (response, code) = index.delete_document_by_filter(json!("hello")).await; snapshot!(code, @"400 Bad Request"); snapshot!(response, @r###" @@ -573,15 +556,14 @@ async fn delete_document_by_filter() { } "###); + let index = shared_does_not_exists_index().await; // index does not exists - let (response, code) = - index.delete_document_by_filter(json!({ "filter": "doggo = bernese"})).await; - snapshot!(code, @"202 Accepted"); - let response = server.wait_task(response.uid()).await; + let (response, _code) = + index.delete_document_by_filter_fail(json!({ "filter": "doggo = bernese"})).await; snapshot!(response, @r###" { "uid": "[uid]", - "indexUid": "tests-documents-errors-delete_document_by_filter", + "indexUid": "DOES_NOT_EXISTS", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -591,7 +573,7 @@ async fn delete_document_by_filter() { "originalFilter": "\"doggo = bernese\"" }, "error": { - "message": "Index `tests-documents-errors-delete_document_by_filter` not found.", + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -603,19 +585,14 @@ async fn delete_document_by_filter() { } "###); - let (response, code) = index.create(None).await; - snapshot!(code, @"202 Accepted"); - server.wait_task(response.uid()).await.succeeded(); - // no filterable are set - let (response, code) = - index.delete_document_by_filter(json!({ "filter": "doggo = bernese"})).await; - snapshot!(code, @"202 Accepted"); - let response = server.wait_task(response.uid()).await; + let index = shared_empty_index().await; + let (response, _code) = + index.delete_document_by_filter_fail(json!({ "filter": "doggo = bernese"})).await; snapshot!(response, @r###" { "uid": "[uid]", - "indexUid": "tests-documents-errors-delete_document_by_filter", + "indexUid": "EMPTY_INDEX", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -637,19 +614,16 @@ async fn delete_document_by_filter() { } "###); - let (response, code) = index.update_settings_filterable_attributes(json!(["doggo"])).await; - snapshot!(code, @"202 Accepted"); - server.wait_task(response.uid()).await.succeeded(); - // not filterable while there is a filterable attribute + let index = shared_index_with_documents().await; let (response, code) = - index.delete_document_by_filter(json!({ "filter": "catto = jorts"})).await; + index.delete_document_by_filter_fail(json!({ "filter": "catto = jorts"})).await; snapshot!(code, @"202 Accepted"); let response = server.wait_task(response.uid()).await; snapshot!(response, @r###" { "uid": "[uid]", - "indexUid": "tests-documents-errors-delete_document_by_filter", + "indexUid": "SHARED_DOCUMENTS", "status": "failed", "type": "documentDeletion", "canceledBy": null, @@ -659,7 +633,7 @@ async fn delete_document_by_filter() { "originalFilter": "\"catto = jorts\"" }, "error": { - "message": "Attribute `catto` is not filterable. Available filterable attributes are: `doggo`.\n1:6 catto = jorts", + "message": "Attribute `catto` is not filterable. Available filterable attributes are: `id`, `title`.\n1:6 catto = jorts", "code": "invalid_document_filter", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid_document_filter" @@ -675,7 +649,7 @@ async fn delete_document_by_filter() { #[actix_rt::test] async fn fetch_document_by_filter() { let server = Server::new_shared(); - let index = server.index("doggo"); + let index = server.unique_index(); index.update_settings_filterable_attributes(json!(["color"])).await; index .add_documents( @@ -772,9 +746,7 @@ async fn fetch_document_by_filter() { #[actix_rt::test] async fn retrieve_vectors() { let server = Server::new_shared(); - let index = server.index("doggo"); - - // GET ALL DOCUMENTS BY QUERY + let index = server.unique_index(); let (response, _code) = index.get_all_documents_raw("?retrieveVectors=tamo").await; snapshot!(response, @r###" { diff --git a/meilisearch/tests/index/errors.rs b/meilisearch/tests/index/errors.rs index bccfd4a90..2b422d685 100644 --- a/meilisearch/tests/index/errors.rs +++ b/meilisearch/tests/index/errors.rs @@ -1,6 +1,6 @@ use meili_snap::*; -use crate::common::Server; +use crate::common::{shared_does_not_exists_index, Server}; use crate::json; #[actix_rt::test] @@ -55,7 +55,7 @@ async fn get_indexes_unknown_field() { async fn create_index_missing_uid() { let server = Server::new_shared(); - let (response, code) = server.create_index(json!({ "primaryKey": "doggo" })).await; + let (response, code) = server.create_index_fail(json!({ "primaryKey": "doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -71,7 +71,7 @@ async fn create_index_missing_uid() { async fn create_index_bad_uid() { let server = Server::new_shared(); - let (response, code) = server.create_index(json!({ "uid": "the best doggo" })).await; + let (response, code) = server.create_index_fail(json!({ "uid": "the best doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -82,7 +82,7 @@ async fn create_index_bad_uid() { } "###); - let (response, code) = server.create_index(json!({ "uid": true })).await; + let (response, code) = server.create_index_fail(json!({ "uid": true })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -99,7 +99,7 @@ async fn create_index_bad_primary_key() { let server = Server::new_shared(); let (response, code) = server - .create_index(json!({ "uid": "doggo", "primaryKey": ["the", "best", "doggo"] })) + .create_index_fail(json!({ "uid": "doggo", "primaryKey": ["the", "best", "doggo"] })) .await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -116,7 +116,8 @@ async fn create_index_bad_primary_key() { async fn create_index_unknown_field() { let server = Server::new_shared(); - let (response, code) = server.create_index(json!({ "uid": "doggo", "doggo": "bernese" })).await; + let (response, code) = + server.create_index_fail(json!({ "uid": "doggo", "doggo": "bernese" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -131,9 +132,7 @@ async fn create_index_unknown_field() { #[actix_rt::test] async fn get_index_bad_uid() { let server = Server::new_shared(); - let index = server.index("the good doggo"); - - let (response, code) = index.get().await; + let (response, code) = server.get_index_fail("the good doggo").await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -148,8 +147,7 @@ async fn get_index_bad_uid() { #[actix_rt::test] async fn update_index_bad_primary_key() { let server = Server::new_shared(); - let index = server.index("doggo"); - + let index = server.unique_index(); let (response, code) = index.update_raw(json!({ "primaryKey": ["doggo"] })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -165,8 +163,7 @@ async fn update_index_bad_primary_key() { #[actix_rt::test] async fn update_index_immutable_uid() { let server = Server::new_shared(); - let index = server.index("doggo"); - + let index = server.unique_index(); let (response, code) = index.update_raw(json!({ "uid": "doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -182,8 +179,7 @@ async fn update_index_immutable_uid() { #[actix_rt::test] async fn update_index_immutable_created_at() { let server = Server::new_shared(); - let index = server.index("doggo"); - + let index = server.unique_index(); let (response, code) = index.update_raw(json!({ "createdAt": "doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -199,8 +195,7 @@ async fn update_index_immutable_created_at() { #[actix_rt::test] async fn update_index_immutable_updated_at() { let server = Server::new_shared(); - let index = server.index("doggo"); - + let index = server.unique_index(); let (response, code) = index.update_raw(json!({ "updatedAt": "doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -216,8 +211,7 @@ async fn update_index_immutable_updated_at() { #[actix_rt::test] async fn update_index_unknown_field() { let server = Server::new_shared(); - let index = server.index("doggo"); - + let index = server.unique_index(); let (response, code) = index.update_raw(json!({ "doggo": "bork" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -233,9 +227,8 @@ async fn update_index_unknown_field() { #[actix_rt::test] async fn update_index_bad_uid() { let server = Server::new_shared(); - let index = server.index("the good doggo"); - - let (response, code) = index.update_raw(json!({ "primaryKey": "doggo" })).await; + let (response, code) = + server.update_raw_index_fail("the good doggo", json!({ "primaryKey": "doggo" })).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { @@ -250,9 +243,7 @@ async fn update_index_bad_uid() { #[actix_rt::test] async fn delete_index_bad_uid() { let server = Server::new_shared(); - let index = server.index("the good doggo"); - - let (response, code) = index.delete().await; + let (response, code) = server.delete_index_fail("the good doggo").await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 2dbb80f6e..fee7eef7d 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -1,15 +1,13 @@ use meili_snap::*; -use crate::common::Server; +use crate::common::{shared_does_not_exists_index, Server}; use crate::json; #[actix_rt::test] async fn search_unexisting_index() { - let server = Server::new_shared(); - let index = server.index("search_unexisting_index"); - + let index = shared_does_not_exists_index().await; let expected_response = json!({ - "message": "Index `search_unexisting_index` not found.", + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -937,8 +935,7 @@ async fn sort_reserved_attribute() { #[actix_rt::test] async fn sort_unsortable_attribute() { let server = Server::new_shared(); - let index = server.index("sort_unsortable_attribute"); - + let index = server.unique_index(); let (response, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; index.wait_task(response.uid()).await.succeeded(); diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index 77be4c13a..54c0b343e 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -15,247 +15,14 @@ mod restrict_searchable; mod search_queue; use meilisearch::Opt; -use once_cell::sync::Lazy; use tempfile::TempDir; -use uuid::Uuid; -use crate::common::index::Index; -use crate::common::{default_settings, Server, Value}; +use crate::common::{ + default_settings, shared_index_with_documents, shared_index_with_nested_documents, Server, + DOCUMENTS, FRUITS_DOCUMENTS, NESTED_DOCUMENTS, SCORE_DOCUMENTS, VECTOR_DOCUMENTS, +}; use crate::json; -static DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "title": "Shazam!", - "id": "287947", - "_vectors": { "manual": [1, 2, 3]}, - }, - { - "title": "Captain Marvel", - "id": "299537", - "_vectors": { "manual": [1, 2, 54] }, - }, - { - "title": "Escape Room", - "id": "522681", - "_vectors": { "manual": [10, -23, 32] }, - }, - { - "title": "How to Train Your Dragon: The Hidden World", - "id": "166428", - "_vectors": { "manual": [-100, 231, 32] }, - }, - { - "title": "Gläss", - "id": "450465", - "_vectors": { "manual": [-100, 340, 90] }, - } - ]) -}); - -pub async fn shared_index_with_documents() -> &'static Index<'static> { - static INDEX: Lazy> = Lazy::new(|| { - let server = Server::new_shared(); - let uuid = Uuid::new_v4(); - let index = server.index(uuid.to_string()); - index - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { - let documents = DOCUMENTS.clone(); - let (response, _code) = INDEX.add_documents(documents, None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - let (response, _code) = INDEX - .update_settings( - json!({"filterableAttributes": ["id", "title"], "sortableAttributes": ["id", "title"]}), - ) - .await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX -} - -static SCORE_DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "title": "Batman the dark knight returns: Part 1", - "id": "A", - }, - { - "title": "Batman the dark knight returns: Part 2", - "id": "B", - }, - { - "title": "Batman Returns", - "id": "C", - }, - { - "title": "Batman", - "id": "D", - }, - { - "title": "Badman", - "id": "E", - } - ]) -}); - -static NESTED_DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "id": 852, - "father": "jean", - "mother": "michelle", - "doggos": [ - { - "name": "bobby", - "age": 2, - }, - { - "name": "buddy", - "age": 4, - }, - ], - "cattos": "pésti", - "_vectors": { "manual": [1, 2, 3]}, - }, - { - "id": 654, - "father": "pierre", - "mother": "sabine", - "doggos": [ - { - "name": "gros bill", - "age": 8, - }, - ], - "cattos": ["simba", "pestiféré"], - "_vectors": { "manual": [1, 2, 54] }, - }, - { - "id": 750, - "father": "romain", - "mother": "michelle", - "cattos": ["enigma"], - "_vectors": { "manual": [10, 23, 32] }, - }, - { - "id": 951, - "father": "jean-baptiste", - "mother": "sophie", - "doggos": [ - { - "name": "turbo", - "age": 5, - }, - { - "name": "fast", - "age": 6, - }, - ], - "cattos": ["moumoute", "gomez"], - "_vectors": { "manual": [10, 23, 32] }, - }, - ]) -}); - -pub async fn shared_index_with_nested_documents() -> &'static Index<'static> { - static INDEX: Lazy> = Lazy::new(|| { - let server = Server::new_shared(); - let uuid = Uuid::new_v4(); - let index = server.index(uuid.to_string()); - index - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { - let documents = NESTED_DOCUMENTS.clone(); - let (response, _code) = INDEX.add_documents(documents, None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - let (response, _code) = INDEX - .update_settings( - json!({"filterableAttributes": ["father", "doggos"], "sortableAttributes": ["doggos"]}), - ) - .await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX -} - -static FRUITS_DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "name": "Exclusive sale: green apple", - "id": "green-apple-boosted", - "BOOST": true - }, - { - "name": "Pear", - "id": "pear", - }, - { - "name": "Red apple gala", - "id": "red-apple-gala", - }, - { - "name": "Exclusive sale: Red Tomato", - "id": "red-tomatoes-boosted", - "BOOST": true - }, - { - "name": "Exclusive sale: Red delicious apple", - "id": "red-delicious-boosted", - "BOOST": true, - } - ]) -}); - -static VECTOR_DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "id": "A", - "description": "the dog barks at the cat", - "_vectors": { - // dimensions [canine, feline, young] - "animal": [0.9, 0.8, 0.05], - // dimensions [negative/positive, energy] - "sentiment": [-0.1, 0.55] - } - }, - { - "id": "B", - "description": "the kitten scratched the beagle", - "_vectors": { - // dimensions [canine, feline, young] - "animal": [0.8, 0.9, 0.5], - // dimensions [negative/positive, energy] - "sentiment": [-0.2, 0.65] - } - }, - { - "id": "C", - "description": "the dog had to stay alone today", - "_vectors": { - // dimensions [canine, feline, young] - "animal": [0.85, 0.02, 0.1], - // dimensions [negative/positive, energy] - "sentiment": [-1.0, 0.1] - } - }, - { - "id": "D", - "description": "the little boy pets the puppy", - "_vectors": { - // dimensions [canine, feline, young] - "animal": [0.8, 0.09, 0.8], - // dimensions [negative/positive, energy] - "sentiment": [0.8, 0.3] - } - }, - ]) -}); - #[actix_rt::test] async fn simple_placeholder_search() { let index = shared_index_with_documents().await; diff --git a/meilisearch/tests/settings/errors.rs b/meilisearch/tests/settings/errors.rs index c0dc1975a..ed1e0298f 100644 --- a/meilisearch/tests/settings/errors.rs +++ b/meilisearch/tests/settings/errors.rs @@ -6,7 +6,7 @@ use crate::json; #[actix_rt::test] async fn settings_bad_displayed_attributes() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "displayedAttributes": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -34,7 +34,7 @@ async fn settings_bad_displayed_attributes() { #[actix_rt::test] async fn settings_bad_searchable_attributes() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "searchableAttributes": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -62,7 +62,7 @@ async fn settings_bad_searchable_attributes() { #[actix_rt::test] async fn settings_bad_filterable_attributes() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "filterableAttributes": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -90,7 +90,7 @@ async fn settings_bad_filterable_attributes() { #[actix_rt::test] async fn settings_bad_sortable_attributes() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "sortableAttributes": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -118,7 +118,7 @@ async fn settings_bad_sortable_attributes() { #[actix_rt::test] async fn settings_bad_ranking_rules() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "rankingRules": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -146,7 +146,7 @@ async fn settings_bad_ranking_rules() { #[actix_rt::test] async fn settings_bad_stop_words() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "stopWords": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -174,7 +174,7 @@ async fn settings_bad_stop_words() { #[actix_rt::test] async fn settings_bad_synonyms() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "synonyms": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -202,7 +202,7 @@ async fn settings_bad_synonyms() { #[actix_rt::test] async fn settings_bad_distinct_attribute() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "distinctAttribute": ["doggo"] })).await; snapshot!(code, @"400 Bad Request"); @@ -230,7 +230,7 @@ async fn settings_bad_distinct_attribute() { #[actix_rt::test] async fn settings_bad_typo_tolerance() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "typoTolerance": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -285,7 +285,7 @@ async fn settings_bad_typo_tolerance() { #[actix_rt::test] async fn settings_bad_faceting() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "faceting": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -313,7 +313,7 @@ async fn settings_bad_faceting() { #[actix_rt::test] async fn settings_bad_pagination() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "pagination": "doggo" })).await; snapshot!(code, @"400 Bad Request"); @@ -341,7 +341,7 @@ async fn settings_bad_pagination() { #[actix_rt::test] async fn settings_bad_search_cutoff_ms() { let server = Server::new_shared(); - let index = server.index("test"); + let index = server.unique_index(); let (response, code) = index.update_settings(json!({ "searchCutoffMs": "doggo" })).await; snapshot!(code, @"400 Bad Request"); diff --git a/milli/src/search/facet/filter.rs b/milli/src/search/facet/filter.rs index e3a99f356..9ce201aca 100644 --- a/milli/src/search/facet/filter.rs +++ b/milli/src/search/facet/filter.rs @@ -75,25 +75,21 @@ impl<'a> Display for FilterError<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::AttributeNotFilterable { attribute, filterable_fields } => { + write!(f, "Attribute `{attribute}` is not filterable.")?; if filterable_fields.is_empty() { - write!( - f, - "Attribute `{}` is not filterable. This index does not have configured filterable attributes.", - attribute, - ) + write!(f, " This index does not have configured filterable attributes.") } else { - let filterables_list = filterable_fields - .iter() - .map(AsRef::as_ref) - .collect::>() - .join(" "); - - write!( - f, - "Attribute `{}` is not filterable. Available filterable attributes are: `{}`.", - attribute, - filterables_list, - ) + write!(f, " Available filterable attributes are: ")?; + let mut filterables_list = + filterable_fields.iter().map(AsRef::as_ref).collect::>(); + filterables_list.sort_unstable(); + for (idx, filterable) in filterables_list.iter().enumerate() { + write!(f, "`{filterable}`")?; + if idx != filterables_list.len() - 1 { + write!(f, ", ")?; + } + } + write!(f, ".") } } Self::TooDeep => write!( From b53a019b07bde3662cb85dd6ae31959124854677 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 10:47:58 +0200 Subject: [PATCH 08/15] fix the initialization problem over the shared indexes with documents --- meilisearch/tests/common/mod.rs | 44 +++++++++++++------------------ meilisearch/tests/index/errors.rs | 2 +- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index 58f531b6d..972c9de60 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -12,6 +12,7 @@ use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; #[allow(unused)] pub use server::{default_settings, Server}; +use tokio::sync::OnceCell; use crate::common::index::Index; @@ -192,25 +193,21 @@ pub static DOCUMENTS: Lazy = Lazy::new(|| { }); pub async fn shared_index_with_documents() -> &'static Index<'static, Shared> { - // We cannot store a `Shared` index directly because we need to do more initialization work later on - static INDEX: Lazy> = Lazy::new(|| { + static INDEX: OnceCell> = OnceCell::const_new(); + INDEX.get_or_init(|| async { let server = Server::new_shared(); - server._index("SHARED_DOCUMENTS").to_shared() - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { + let index = server._index("SHARED_DOCUMENTS").to_shared(); let documents = DOCUMENTS.clone(); - let (response, _code) = INDEX._add_documents(documents, None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - let (response, _code) = INDEX + let (response, _code) = index._add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); + let (response, _code) = index ._update_settings( json!({"filterableAttributes": ["id", "title"], "sortableAttributes": ["id", "title"]}), ) .await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX + index.wait_task(response.uid()).await.succeeded(); + index + }).await } pub static SCORE_DOCUMENTS: Lazy = Lazy::new(|| { @@ -298,24 +295,21 @@ pub static NESTED_DOCUMENTS: Lazy = Lazy::new(|| { }); pub async fn shared_index_with_nested_documents() -> &'static Index<'static, Shared> { - static INDEX: Lazy> = Lazy::new(|| { + static INDEX: OnceCell> = OnceCell::const_new(); + INDEX.get_or_init(|| async { let server = Server::new_shared(); - server._index("SHARED_NESTED_DOCUMENTS").to_shared() - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { + let index = server._index("SHARED_NESTED_DOCUMENTS").to_shared(); let documents = NESTED_DOCUMENTS.clone(); - let (response, _code) = INDEX._add_documents(documents, None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - let (response, _code) = INDEX + let (response, _code) = index._add_documents(documents, None).await; + index.wait_task(response.uid()).await.succeeded(); + let (response, _code) = index ._update_settings( json!({"filterableAttributes": ["father", "doggos"], "sortableAttributes": ["doggos"]}), ) .await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX + index.wait_task(response.uid()).await.succeeded(); + index + }).await } pub static FRUITS_DOCUMENTS: Lazy = Lazy::new(|| { diff --git a/meilisearch/tests/index/errors.rs b/meilisearch/tests/index/errors.rs index 2b422d685..9c677ee12 100644 --- a/meilisearch/tests/index/errors.rs +++ b/meilisearch/tests/index/errors.rs @@ -1,6 +1,6 @@ use meili_snap::*; -use crate::common::{shared_does_not_exists_index, Server}; +use crate::common::Server; use crate::json; #[actix_rt::test] From 6666c57880ce2a187f3680ecc06dfe3728d73fcc Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 11:20:42 +0200 Subject: [PATCH 09/15] reduce the number of thread spawned by milli --- meilisearch/tests/common/server.rs | 3 ++- meilisearch/tests/documents/errors.rs | 9 +++++---- meilisearch/tests/tasks/mod.rs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index e69b3eb6e..bedfc9283 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use std::path::Path; -use std::str::FromStr as _; +use std::str::FromStr; use std::time::Duration; use actix_http::body::MessageBody; @@ -345,6 +345,7 @@ pub fn default_settings(dir: impl AsRef) -> Opt { // memory has to be unlimited because several meilisearch are running in test context. max_indexing_memory: MaxMemory::unlimited(), skip_index_budget: true, + // We cannot use more than 1 indexing threads otherwise some tests become non-deterministic max_indexing_threads: MaxThreads::from_str("1").unwrap(), }, experimental_enable_metrics: false, diff --git a/meilisearch/tests/documents/errors.rs b/meilisearch/tests/documents/errors.rs index 2c5f2a965..280073f51 100644 --- a/meilisearch/tests/documents/errors.rs +++ b/meilisearch/tests/documents/errors.rs @@ -651,7 +651,7 @@ async fn fetch_document_by_filter() { let server = Server::new_shared(); let index = server.unique_index(); index.update_settings_filterable_attributes(json!(["color"])).await; - index + let (task, _code) = index .add_documents( json!([ { "id": 0, "color": "red" }, @@ -662,7 +662,7 @@ async fn fetch_document_by_filter() { Some("id"), ) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await.succeeded(); let (response, code) = index.get_document_by_filter(json!(null)).await; snapshot!(code, @"400 Bad Request"); @@ -745,8 +745,9 @@ async fn fetch_document_by_filter() { #[actix_rt::test] async fn retrieve_vectors() { - let server = Server::new_shared(); - let index = server.unique_index(); + let index = shared_empty_index().await; + + // GET ALL DOCUMENTS BY QUERY let (response, _code) = index.get_all_documents_raw("?retrieveVectors=tamo").await; snapshot!(response, @r###" { diff --git a/meilisearch/tests/tasks/mod.rs b/meilisearch/tests/tasks/mod.rs index 23ba669ca..c59313885 100644 --- a/meilisearch/tests/tasks/mod.rs +++ b/meilisearch/tests/tasks/mod.rs @@ -66,8 +66,8 @@ async fn list_tasks() { async fn list_tasks_with_star_filters() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task, _code) = index.create(None).await; + index.wait_task(task.uid()).await; index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; From 9372c34dab58fa3b377b9723c3d27821699fc867 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 13:56:44 +0200 Subject: [PATCH 10/15] prepare the tests to share indexes with api key --- meilisearch/tests/auth/mod.rs | 60 ------------- meilisearch/tests/auth/tenant_token.rs | 32 +------ meilisearch/tests/common/mod.rs | 5 ++ meilisearch/tests/common/server.rs | 73 +++++++++++++++- meilisearch/tests/search/mod.rs | 36 ++++++++ meilisearch/tests/search/multi.rs | 112 +++++++++++++++++++++++++ 6 files changed, 225 insertions(+), 93 deletions(-) diff --git a/meilisearch/tests/auth/mod.rs b/meilisearch/tests/auth/mod.rs index 781b2dcc0..04c2d18b1 100644 --- a/meilisearch/tests/auth/mod.rs +++ b/meilisearch/tests/auth/mod.rs @@ -5,63 +5,3 @@ mod payload; mod tenant_token; mod tenant_token_multi_search; - -use actix_web::http::StatusCode; - -use crate::common::{Server, Value}; -use crate::json; - -impl Server { - pub fn use_api_key(&mut self, api_key: impl AsRef) { - self.service.api_key = Some(api_key.as_ref().to_string()); - } - - /// Fetch and use the default admin key for nexts http requests. - pub async fn use_admin_key(&mut self, master_key: impl AsRef) { - self.use_api_key(master_key); - let (response, code) = self.list_api_keys("").await; - assert_eq!(200, code, "{:?}", response); - let admin_key = &response["results"][1]["key"]; - self.use_api_key(admin_key.as_str().unwrap()); - } - - pub async fn add_api_key(&self, content: Value) -> (Value, StatusCode) { - let url = "/keys"; - self.service.post(url, content).await - } - - pub async fn get_api_key(&self, key: impl AsRef) -> (Value, StatusCode) { - let url = format!("/keys/{}", key.as_ref()); - self.service.get(url).await - } - - pub async fn patch_api_key(&self, key: impl AsRef, content: Value) -> (Value, StatusCode) { - let url = format!("/keys/{}", key.as_ref()); - self.service.patch(url, content).await - } - - pub async fn list_api_keys(&self, params: &str) -> (Value, StatusCode) { - let url = format!("/keys{params}"); - self.service.get(url).await - } - - pub async fn delete_api_key(&self, key: impl AsRef) -> (Value, StatusCode) { - let url = format!("/keys/{}", key.as_ref()); - self.service.delete(url).await - } - - pub async fn dummy_request( - &self, - method: impl AsRef, - url: impl AsRef, - ) -> (Value, StatusCode) { - match method.as_ref() { - "POST" => self.service.post(url, json!({})).await, - "PUT" => self.service.put(url, json!({})).await, - "PATCH" => self.service.patch(url, json!({})).await, - "GET" => self.service.get(url).await, - "DELETE" => self.service.delete(url).await, - _ => unreachable!(), - } - } -} diff --git a/meilisearch/tests/auth/tenant_token.rs b/meilisearch/tests/auth/tenant_token.rs index 5e8a75c36..2e3b228d3 100644 --- a/meilisearch/tests/auth/tenant_token.rs +++ b/meilisearch/tests/auth/tenant_token.rs @@ -6,7 +6,7 @@ use once_cell::sync::Lazy; use time::{Duration, OffsetDateTime}; use super::authorization::{ALL_ACTIONS, AUTHORIZATIONS}; -use crate::common::{Server, Value}; +use crate::common::{Server, Value, DOCUMENTS}; use crate::json; fn generate_tenant_token( @@ -22,36 +22,6 @@ fn generate_tenant_token( .unwrap() } -static DOCUMENTS: Lazy = Lazy::new(|| { - json!([ - { - "title": "Shazam!", - "id": "287947", - "color": ["green", "blue"] - }, - { - "title": "Captain Marvel", - "id": "299537", - "color": ["yellow", "blue"] - }, - { - "title": "Escape Room", - "id": "522681", - "color": ["yellow", "red"] - }, - { - "title": "How to Train Your Dragon: The Hidden World", - "id": "166428", - "color": ["green", "red"] - }, - { - "title": "Glass", - "id": "450465", - "color": ["blue", "red"] - } - ]) -}); - static INVALID_RESPONSE: Lazy = Lazy::new(|| { json!({ "message": null, diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index 972c9de60..9a594f8f1 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -167,26 +167,31 @@ pub static DOCUMENTS: Lazy = Lazy::new(|| { { "title": "Shazam!", "id": "287947", + "color": ["green", "blue"], "_vectors": { "manual": [1, 2, 3]}, }, { "title": "Captain Marvel", "id": "299537", + "color": ["yellow", "blue"], "_vectors": { "manual": [1, 2, 54] }, }, { "title": "Escape Room", "id": "522681", + "color": ["yellow", "red"], "_vectors": { "manual": [10, -23, 32] }, }, { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": ["green", "red"], "_vectors": { "manual": [-100, 231, 32] }, }, { "title": "Gläss", "id": "450465", + "color": ["blue", "red"], "_vectors": { "manual": [-100, 340, 90] }, } ]) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index bedfc9283..2a5d78241 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -14,6 +14,7 @@ use meilisearch::option::{IndexerOpts, MaxMemory, MaxThreads, Opt}; use meilisearch::{analytics, create_app, setup_meilisearch, SubscriberForSecondLayer}; use once_cell::sync::Lazy; use tempfile::TempDir; +use tokio::sync::OnceCell; use tokio::time::sleep; use tracing::level_filters::LevelFilter; use tracing_subscriber::Layer; @@ -34,9 +35,12 @@ pub struct Server { } pub static TEST_TEMP_DIR: Lazy = Lazy::new(|| TempDir::new().unwrap()); -pub static TEST_SHARED_INSTANCE: Lazy> = Lazy::new(Server::init_new_shared_instance); impl Server { + fn to_shared(self) -> Server { + Server { service: self.service, _dir: self._dir, _marker: PhantomData } + } + pub async fn new() -> Self { let dir = TempDir::new().unwrap(); @@ -82,6 +86,34 @@ impl Server { Ok(Server { service, _dir: None, _marker: PhantomData }) } + pub fn use_api_key(&mut self, api_key: impl AsRef) { + self.service.api_key = Some(api_key.as_ref().to_string()); + } + + /// Fetch and use the default admin key for nexts http requests. + pub async fn use_admin_key(&mut self, master_key: impl AsRef) { + self.use_api_key(master_key); + let (response, code) = self.list_api_keys("").await; + assert_eq!(200, code, "{:?}", response); + let admin_key = &response["results"][1]["key"]; + self.use_api_key(admin_key.as_str().unwrap()); + } + + pub async fn add_api_key(&self, content: Value) -> (Value, StatusCode) { + let url = "/keys"; + self.service.post(url, content).await + } + + pub async fn patch_api_key(&self, key: impl AsRef, content: Value) -> (Value, StatusCode) { + let url = format!("/keys/{}", key.as_ref()); + self.service.patch(url, content).await + } + + pub async fn delete_api_key(&self, key: impl AsRef) -> (Value, StatusCode) { + let url = format!("/keys/{}", key.as_ref()); + self.service.delete(url).await + } + /// Returns a view to an index. There is no guarantee that the index exists. pub fn index(&self, uid: impl AsRef) -> Index<'_> { self.index_with_encoder(uid, Encoder::Plain) @@ -157,7 +189,19 @@ impl Server { } pub fn new_shared() -> &'static Server { - &TEST_SHARED_INSTANCE + static SERVER: Lazy> = Lazy::new(Server::init_new_shared_instance); + &SERVER + } + + pub async fn new_shared_with_admin_key() -> &'static Server { + static SERVER: OnceCell> = OnceCell::const_new(); + SERVER + .get_or_init(|| async { + let mut server = Server::new_auth().await; + server.use_admin_key("MASTER_KEY").await; + server.to_shared() + }) + .await } /// You shouldn't access random indexes on a shared instance thus this method @@ -243,6 +287,31 @@ impl Server { .await } + pub async fn list_api_keys(&self, params: &str) -> (Value, StatusCode) { + let url = format!("/keys{params}"); + self.service.get(url).await + } + + pub async fn dummy_request( + &self, + method: impl AsRef, + url: impl AsRef, + ) -> (Value, StatusCode) { + match method.as_ref() { + "POST" => self.service.post(url, json!({})).await, + "PUT" => self.service.put(url, json!({})).await, + "PATCH" => self.service.patch(url, json!({})).await, + "GET" => self.service.get(url).await, + "DELETE" => self.service.delete(url).await, + _ => unreachable!(), + } + } + + pub async fn get_api_key(&self, key: impl AsRef) -> (Value, StatusCode) { + let url = format!("/keys/{}", key.as_ref()); + self.service.get(url).await + } + pub(super) fn _index(&self, uid: impl AsRef) -> Index<'_> { Index { uid: uid.as_ref().to_string(), diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index 54c0b343e..3c406cd5f 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -742,6 +742,10 @@ async fn test_score_details() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -1168,6 +1172,10 @@ async fn experimental_feature_vector_store() { { "title": "Shazam!", "id": "287947", + "color": [ + "green", + "blue" + ], "_vectors": { "manual": { "embeddings": [ @@ -1185,6 +1193,10 @@ async fn experimental_feature_vector_store() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": { "embeddings": [ @@ -1202,6 +1214,10 @@ async fn experimental_feature_vector_store() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": { "embeddings": [ @@ -1219,6 +1235,10 @@ async fn experimental_feature_vector_store() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": { "embeddings": [ @@ -1236,6 +1256,10 @@ async fn experimental_feature_vector_store() { { "title": "Escape Room", "id": "522681", + "color": [ + "yellow", + "red" + ], "_vectors": { "manual": { "embeddings": [ @@ -1502,6 +1526,10 @@ async fn simple_search_with_strange_synonyms() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -1523,6 +1551,10 @@ async fn simple_search_with_strange_synonyms() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -1544,6 +1576,10 @@ async fn simple_search_with_strange_synonyms() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, diff --git a/meilisearch/tests/search/multi.rs b/meilisearch/tests/search/multi.rs index 89b06c68c..08ad0b18c 100644 --- a/meilisearch/tests/search/multi.rs +++ b/meilisearch/tests/search/multi.rs @@ -107,6 +107,10 @@ async fn simple_search_single_index() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -128,6 +132,10 @@ async fn simple_search_single_index() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -168,6 +176,10 @@ async fn federation_single_search_single_index() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -287,6 +299,10 @@ async fn federation_two_search_single_index() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -303,6 +319,10 @@ async fn federation_two_search_single_index() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -454,6 +474,10 @@ async fn simple_search_two_indexes() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -555,6 +579,10 @@ async fn federation_two_search_two_indexes() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -673,6 +701,10 @@ async fn federation_multiple_search_multiple_indexes() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -735,6 +767,10 @@ async fn federation_multiple_search_multiple_indexes() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -751,6 +787,10 @@ async fn federation_multiple_search_multiple_indexes() { { "title": "Escape Room", "id": "522681", + "color": [ + "yellow", + "red" + ], "_vectors": { "manual": [ 10.0, @@ -852,6 +892,10 @@ async fn federation_multiple_search_multiple_indexes() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2053,6 +2097,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2070,6 +2118,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "Escape Room", "id": "522681", + "color": [ + "yellow", + "red" + ], "_vectors": { "manual": [ 10.0, @@ -2087,6 +2139,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2104,6 +2160,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2121,6 +2181,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "Shazam!", "id": "287947", + "color": [ + "green", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2158,6 +2222,10 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2341,6 +2409,10 @@ async fn federation_sort_different_ranking_rules() { { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2358,6 +2430,10 @@ async fn federation_sort_different_ranking_rules() { { "title": "Escape Room", "id": "522681", + "color": [ + "yellow", + "red" + ], "_vectors": { "manual": [ 10.0, @@ -2375,6 +2451,10 @@ async fn federation_sort_different_ranking_rules() { { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2392,6 +2472,10 @@ async fn federation_sort_different_ranking_rules() { { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2409,6 +2493,10 @@ async fn federation_sort_different_ranking_rules() { { "title": "Shazam!", "id": "287947", + "color": [ + "green", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2622,6 +2710,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2659,6 +2751,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "Escape Room", "id": "522681", + "color": [ + "yellow", + "red" + ], "_vectors": { "manual": [ 10.0, @@ -2676,6 +2772,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "Gläss", "id": "450465", + "color": [ + "blue", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2693,6 +2793,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "How to Train Your Dragon: The Hidden World", "id": "166428", + "color": [ + "green", + "red" + ], "_vectors": { "manual": [ -100.0, @@ -2710,6 +2814,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "Shazam!", "id": "287947", + "color": [ + "green", + "blue" + ], "_vectors": { "manual": [ 1.0, @@ -2767,6 +2875,10 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() { "title": "Captain Marvel", "id": "299537", + "color": [ + "yellow", + "blue" + ], "_vectors": { "manual": [ 1.0, From 68f885f1c4acda6174afdb733a8e6ad01941085f Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 14:45:59 +0200 Subject: [PATCH 11/15] fix two snapshots --- meilisearch/tests/vector/rest.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meilisearch/tests/vector/rest.rs b/meilisearch/tests/vector/rest.rs index 370c1ecf7..317ca8676 100644 --- a/meilisearch/tests/vector/rest.rs +++ b/meilisearch/tests/vector/rest.rs @@ -941,7 +941,7 @@ async fn bad_settings() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -1125,7 +1125,7 @@ async fn server_returns_bad_request() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "settingsUpdate", @@ -1154,7 +1154,7 @@ async fn server_returns_bad_request() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "documentAdditionOrUpdate", @@ -1839,7 +1839,7 @@ async fn server_custom_header() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 1, + "uid": "[uid]", "indexUid": "doggo", "status": "failed", "type": "settingsUpdate", @@ -1881,7 +1881,7 @@ async fn server_custom_header() { let task = server.wait_task(response.uid()).await; snapshot!(task, @r###" { - "uid": 2, + "uid": "[uid]", "indexUid": "doggo", "status": "succeeded", "type": "settingsUpdate", From ded3cd0dd67a5942474e10c44079e2f920f1b4ca Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 15:03:54 +0200 Subject: [PATCH 12/15] an additionnal 30% of perf for the tests --- meilisearch/tests/common/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index 2a5d78241..a5430db2f 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -414,8 +414,8 @@ pub fn default_settings(dir: impl AsRef) -> Opt { // memory has to be unlimited because several meilisearch are running in test context. max_indexing_memory: MaxMemory::unlimited(), skip_index_budget: true, - // We cannot use more than 1 indexing threads otherwise some tests become non-deterministic - max_indexing_threads: MaxThreads::from_str("1").unwrap(), + // Having 2 threads makes the tests way faster + max_indexing_threads: MaxThreads::from_str("2").unwrap(), }, experimental_enable_metrics: false, ..Parser::parse_from(None as Option<&str>) From 7a5a38f870297970449dae376e26b692da1a59ab Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 15:09:12 +0200 Subject: [PATCH 13/15] fix a sync issue on empty indexes --- meilisearch/tests/common/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/meilisearch/tests/common/mod.rs b/meilisearch/tests/common/mod.rs index 9a594f8f1..afbd5a2f5 100644 --- a/meilisearch/tests/common/mod.rs +++ b/meilisearch/tests/common/mod.rs @@ -149,17 +149,17 @@ pub async fn shared_does_not_exists_index() -> &'static Index<'static, Shared> { } pub async fn shared_empty_index() -> &'static Index<'static, Shared> { - static INDEX: Lazy> = Lazy::new(|| { - let server = Server::new_shared(); - server._index("EMPTY_INDEX").to_shared() - }); - let index = Lazy::get(&INDEX); - // That means the lazy has never been initialized, we need to create the index and index the documents - if index.is_none() { - let (response, _code) = INDEX._create(None).await; - INDEX.wait_task(response.uid()).await.succeeded(); - } - &INDEX + static INDEX: OnceCell> = OnceCell::const_new(); + + INDEX + .get_or_init(|| async { + let server = Server::new_shared(); + let index = server._index("EMPTY_INDEX").to_shared(); + let (response, _code) = index._create(None).await; + index.wait_task(response.uid()).await.succeeded(); + index + }) + .await } pub static DOCUMENTS: Lazy = Lazy::new(|| { From bb1283222eaf15cf7efe074f57ebcdb7a265e7fa Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 15:10:56 +0200 Subject: [PATCH 14/15] make clippy happy --- meilisearch/tests/common/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index a5430db2f..ab3717e22 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -37,7 +37,7 @@ pub struct Server { pub static TEST_TEMP_DIR: Lazy = Lazy::new(|| TempDir::new().unwrap()); impl Server { - fn to_shared(self) -> Server { + fn into_shared(self) -> Server { Server { service: self.service, _dir: self._dir, _marker: PhantomData } } @@ -199,7 +199,7 @@ impl Server { .get_or_init(|| async { let mut server = Server::new_auth().await; server.use_admin_key("MASTER_KEY").await; - server.to_shared() + server.into_shared() }) .await } From c45706936732aef16d5a07545e47534d59901a91 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 30 Jul 2024 15:41:51 +0200 Subject: [PATCH 15/15] ensure a test is 100% not flaky --- meilisearch/tests/vector/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/meilisearch/tests/vector/mod.rs b/meilisearch/tests/vector/mod.rs index 79bc41d19..66f1f87e7 100644 --- a/meilisearch/tests/vector/mod.rs +++ b/meilisearch/tests/vector/mod.rs @@ -1,10 +1,13 @@ mod rest; mod settings; +use std::str::FromStr; + use meili_snap::{json_string, snapshot}; +use meilisearch::option::MaxThreads; use crate::common::index::Index; -use crate::common::{GetAllDocumentsOptions, Server}; +use crate::common::{default_settings, GetAllDocumentsOptions, Server}; use crate::json; #[actix_rt::test] @@ -486,7 +489,11 @@ async fn user_provided_embeddings_error() { #[actix_rt::test] async fn user_provided_vectors_error() { - let server = Server::new().await; + let temp = tempfile::tempdir().unwrap(); + let mut options = default_settings(temp.path()); + // If we have more than one indexing thread the error messages below may become inconsistent + options.indexer_options.max_indexing_threads = MaxThreads::from_str("1").unwrap(); + let server = Server::new_with_options(options).await.unwrap(); let index = generate_default_user_provided_documents(&server).await;