From 953d3a44bd92f359165ffa77b8bdfbec3b3535bd Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 18 Jul 2024 17:26:43 +0200 Subject: [PATCH] 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");