From 5539a1904a76a34ea1c292b521249478b41c1bfb Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Sat, 28 Sep 2024 11:05:52 +0200 Subject: [PATCH 1/9] test: improve performance of create_index.rs --- meilisearch/tests/index/create_index.rs | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/meilisearch/tests/index/create_index.rs b/meilisearch/tests/index/create_index.rs index b51ccab51..16a6e0678 100644 --- a/meilisearch/tests/index/create_index.rs +++ b/meilisearch/tests/index/create_index.rs @@ -17,7 +17,7 @@ async fn create_index_no_primary_key() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(0).await; + let response = index.wait_task(response.uid()).await; assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -34,7 +34,7 @@ async fn create_index_with_gzip_encoded_request() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(0).await; + let response = index.wait_task(response.uid()).await; assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -82,7 +82,7 @@ async fn create_index_with_zlib_encoded_request() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(0).await; + let response = index.wait_task(response.uid()).await; assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -99,7 +99,7 @@ async fn create_index_with_brotli_encoded_request() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(0).await; + let response = index.wait_task(response.uid()).await; assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -116,7 +116,7 @@ async fn create_index_with_primary_key() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(0).await; + let response = index.wait_task(response.uid()).await; assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -129,10 +129,10 @@ async fn create_index_with_invalid_primary_key() { let server = Server::new().await; let index = server.index("movies"); - let (_response, code) = index.add_documents(document, Some("title")).await; + let (response, code) = index.add_documents(document, Some("title")).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(response.uid()).await; let (response, code) = index.get().await; assert_eq!(code, 200); @@ -147,13 +147,13 @@ async fn test_create_multiple_indexes() { let index3 = server.index("test3"); let index4 = server.index("test4"); - index1.create(None).await; - index2.create(None).await; - index3.create(None).await; + let (task1, _) = index1.create(None).await; + let (task2, _) = index2.create(None).await; + let (task3, _) = index3.create(None).await; - index1.wait_task(0).await; - index1.wait_task(1).await; - index1.wait_task(2).await; + index1.wait_task(task1.uid()).await.succeeded(); + index2.wait_task(task2.uid()).await.succeeded(); + index3.wait_task(task3.uid()).await.succeeded(); assert_eq!(index1.get().await.1, 200); assert_eq!(index2.get().await.1, 200); @@ -169,9 +169,9 @@ async fn error_create_existing_index() { assert_eq!(code, 202); - index.create(Some("primary")).await; + let (task, _) = index.create(Some("primary")).await; - let response = index.wait_task(1).await; + let response = index.wait_task(task.uid()).await; let expected_response = json!({ "message": "Index `test` already exists.", From 84b4219a4fa153c83a31f00fc45b7545d66cf0a6 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Sun, 29 Sep 2024 10:16:31 +0200 Subject: [PATCH 2/9] test: improve delete_index.rs --- meilisearch/tests/index/delete_index.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/meilisearch/tests/index/delete_index.rs b/meilisearch/tests/index/delete_index.rs index e404a6003..8e238dad3 100644 --- a/meilisearch/tests/index/delete_index.rs +++ b/meilisearch/tests/index/delete_index.rs @@ -5,19 +5,19 @@ use crate::json; async fn create_and_delete_index() { let server = Server::new().await; let index = server.index("test"); - let (_response, code) = index.create(None).await; + let (response, code) = index.create(None).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(response.uid()).await.succeeded(); assert_eq!(index.get().await.1, 200); - let (_response, code) = index.delete().await; + let (response, code) = index.delete().await; assert_eq!(code, 202); - index.wait_task(1).await; + index.wait_task(response.uid()).await.succeeded(); assert_eq!(index.get().await.1, 404); } @@ -26,7 +26,7 @@ async fn create_and_delete_index() { async fn error_delete_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.delete().await; + let (task, code) = index.delete().await; assert_eq!(code, 202); @@ -37,7 +37,7 @@ async fn error_delete_unexisting_index() { "link": "https://docs.meilisearch.com/errors#index_not_found" }); - let response = index.wait_task(0).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "failed"); assert_eq!(response["error"], expected_response); } From 2654ce6e6c4d256b37e098e8d1be12af0d82e2eb Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Tue, 1 Oct 2024 17:01:47 +0200 Subject: [PATCH 3/9] use shared servers --- meilisearch/tests/index/delete_index.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/meilisearch/tests/index/delete_index.rs b/meilisearch/tests/index/delete_index.rs index 8e238dad3..a6d61882e 100644 --- a/meilisearch/tests/index/delete_index.rs +++ b/meilisearch/tests/index/delete_index.rs @@ -3,8 +3,8 @@ use crate::json; #[actix_rt::test] async fn create_and_delete_index() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared(); + let index = server.unique_index(); let (response, code) = index.create(None).await; assert_eq!(code, 202); @@ -24,14 +24,18 @@ async fn create_and_delete_index() { #[actix_rt::test] async fn error_delete_unexisting_index() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared(); + let index = server.unique_index(); let (task, code) = index.delete().await; assert_eq!(code, 202); + let msg = format!( + "Index `{}` not found.", + task["indexUid"].as_str().expect("indexUid should exist").trim_matches('"') + ); let expected_response = json!({ - "message": "Index `test` not found.", + "message": msg, "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" @@ -44,8 +48,8 @@ async fn error_delete_unexisting_index() { #[actix_rt::test] async fn loop_delete_add_documents() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared(); + let index = server.unique_index(); let documents = json!([{"id": 1, "field1": "hello"}]); let mut tasks = Vec::new(); for _ in 0..50 { From 17571805b47d9117fc75afc5abdded64fa9424e8 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Tue, 1 Oct 2024 17:27:27 +0200 Subject: [PATCH 4/9] use shared servers --- meilisearch/tests/common/server.rs | 5 +++ meilisearch/tests/index/create_index.rs | 44 ++++++++++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/meilisearch/tests/common/server.rs b/meilisearch/tests/common/server.rs index 6d331ebbc..200f6a141 100644 --- a/meilisearch/tests/common/server.rs +++ b/meilisearch/tests/common/server.rs @@ -309,6 +309,11 @@ impl Server { } } + pub fn unique_index_with_encoder(&self, encoder: Encoder) -> Index<'_> { + let uuid = Uuid::new_v4(); + Index { uid: uuid.to_string(), service: &self.service, encoder, marker: PhantomData } + } + pub(super) async fn _create_index(&self, body: Value) -> (Value, StatusCode) { self.service.post("/indexes", body).await } diff --git a/meilisearch/tests/index/create_index.rs b/meilisearch/tests/index/create_index.rs index 16a6e0678..528e84b8e 100644 --- a/meilisearch/tests/index/create_index.rs +++ b/meilisearch/tests/index/create_index.rs @@ -9,8 +9,8 @@ use crate::json; #[actix_rt::test] async fn create_index_no_primary_key() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared(); + let index = server.unique_index(); let (response, code) = index.create(None).await; assert_eq!(code, 202); @@ -26,8 +26,8 @@ async fn create_index_no_primary_key() { #[actix_rt::test] async fn create_index_with_gzip_encoded_request() { - let server = Server::new().await; - let index = server.index_with_encoder("test", Encoder::Gzip); + let server = Server::new_shared(); + let index = server.unique_index_with_encoder(Encoder::Gzip); let (response, code) = index.create(None).await; assert_eq!(code, 202); @@ -43,7 +43,7 @@ async fn create_index_with_gzip_encoded_request() { #[actix_rt::test] async fn create_index_with_gzip_encoded_request_and_receiving_brotli_encoded_response() { - let server = Server::new().await; + let server = Server::new_shared(); let app = server.init_web_app().await; let body = serde_json::to_string(&json!({ @@ -68,14 +68,14 @@ async fn create_index_with_gzip_encoded_request_and_receiving_brotli_encoded_res let parsed_response = serde_json::from_slice::(decoded.into().as_ref()).expect("Expecting valid json"); - assert_eq!(parsed_response["taskUid"], 0); + assert_eq!(parsed_response["taskUid"], 3); assert_eq!(parsed_response["indexUid"], "test"); } #[actix_rt::test] async fn create_index_with_zlib_encoded_request() { - let server = Server::new().await; - let index = server.index_with_encoder("test", Encoder::Deflate); + let server = Server::new_shared(); + let index = server.unique_index_with_encoder(Encoder::Deflate); let (response, code) = index.create(None).await; assert_eq!(code, 202); @@ -91,8 +91,8 @@ async fn create_index_with_zlib_encoded_request() { #[actix_rt::test] async fn create_index_with_brotli_encoded_request() { - let server = Server::new().await; - let index = server.index_with_encoder("test", Encoder::Brotli); + let server = Server::new_shared(); + let index = server.unique_index_with_encoder(Encoder::Brotli); let (response, code) = index.create(None).await; assert_eq!(code, 202); @@ -108,8 +108,8 @@ async fn create_index_with_brotli_encoded_request() { #[actix_rt::test] async fn create_index_with_primary_key() { - let server = Server::new().await; - let index = server.index("test"); + let server = Server::new_shared(); + let index = server.unique_index(); let (response, code) = index.create(Some("primary")).await; assert_eq!(code, 202); @@ -127,8 +127,8 @@ async fn create_index_with_primary_key() { async fn create_index_with_invalid_primary_key() { let document = json!([ { "id": 2, "title": "Pride and Prejudice" } ]); - let server = Server::new().await; - let index = server.index("movies"); + let server = Server::new_shared(); + let index = server.unique_index(); let (response, code) = index.add_documents(document, Some("title")).await; assert_eq!(code, 202); @@ -142,10 +142,10 @@ async fn create_index_with_invalid_primary_key() { #[actix_rt::test] async fn test_create_multiple_indexes() { let server = Server::new().await; - let index1 = server.index("test1"); - let index2 = server.index("test2"); - let index3 = server.index("test3"); - let index4 = server.index("test4"); + let index1 = server.unique_index(); + let index2 = server.unique_index(); + let index3 = server.unique_index(); + let index4 = server.unique_index(); let (task1, _) = index1.create(None).await; let (task2, _) = index2.create(None).await; @@ -164,7 +164,7 @@ async fn test_create_multiple_indexes() { #[actix_rt::test] async fn error_create_existing_index() { let server = Server::new().await; - let index = server.index("test"); + let index = server.unique_index(); let (_, code) = index.create(Some("primary")).await; assert_eq!(code, 202); @@ -172,9 +172,13 @@ async fn error_create_existing_index() { let (task, _) = index.create(Some("primary")).await; let response = index.wait_task(task.uid()).await; + let msg = format!( + "Index `{}` already exists.", + task["indexUid"].as_str().expect("indexUid should exist").trim_matches('"') + ); let expected_response = json!({ - "message": "Index `test` already exists.", + "message": msg, "code": "index_already_exists", "type": "invalid_request", "link":"https://docs.meilisearch.com/errors#index_already_exists" From 2a18917af309e053ef48cc09a6c875eddf03f5d8 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Wed, 2 Oct 2024 16:23:21 +0200 Subject: [PATCH 5/9] add delete_index_fail function --- meilisearch/tests/common/index.rs | 20 ++++++++++++++++++++ meilisearch/tests/index/delete_index.rs | 13 ++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/meilisearch/tests/common/index.rs b/meilisearch/tests/common/index.rs index 381bd1cb4..784067c2d 100644 --- a/meilisearch/tests/common/index.rs +++ b/meilisearch/tests/common/index.rs @@ -272,6 +272,20 @@ impl<'a> Index<'a, Shared> { } (task, code) } + + pub async fn delete_index_fail(&self) -> (Value, StatusCode) { + let (mut task, code) = self._delete().await; + if code.is_success() { + task = self.wait_task(task.uid()).await; + if task.is_success() { + panic!( + "`delete_index_fail` succeeded: {}", + serde_json::to_string_pretty(&task).unwrap() + ); + } + } + (task, code) + } } #[allow(dead_code)] @@ -314,6 +328,12 @@ impl Index<'_, State> { }); self.service.post_encoded("/indexes", body, self.encoder).await } + + pub(super) async fn _delete(&self) -> (Value, StatusCode) { + let url = format!("/indexes/{}", urlencode(self.uid.as_ref())); + self.service.delete(url).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); diff --git a/meilisearch/tests/index/delete_index.rs b/meilisearch/tests/index/delete_index.rs index a6d61882e..03185d21a 100644 --- a/meilisearch/tests/index/delete_index.rs +++ b/meilisearch/tests/index/delete_index.rs @@ -1,4 +1,4 @@ -use crate::common::Server; +use crate::common::{shared_does_not_exists_index, Server}; use crate::json; #[actix_rt::test] @@ -24,18 +24,13 @@ async fn create_and_delete_index() { #[actix_rt::test] async fn error_delete_unexisting_index() { - let server = Server::new_shared(); - let index = server.unique_index(); - let (task, code) = index.delete().await; + let index = shared_does_not_exists_index().await; + let (task, code) = index.delete_index_fail().await; assert_eq!(code, 202); - let msg = format!( - "Index `{}` not found.", - task["indexUid"].as_str().expect("indexUid should exist").trim_matches('"') - ); let expected_response = json!({ - "message": msg, + "message": "Index `DOES_NOT_EXISTS` not found.", "code": "index_not_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index_not_found" From c0912aa6856f16b711df116d14f88e921e945faf Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 7 Oct 2024 16:29:47 +0200 Subject: [PATCH 6/9] add missing shared servers --- meilisearch/tests/index/create_index.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch/tests/index/create_index.rs b/meilisearch/tests/index/create_index.rs index 47a2f0f4a..110690638 100644 --- a/meilisearch/tests/index/create_index.rs +++ b/meilisearch/tests/index/create_index.rs @@ -152,7 +152,7 @@ async fn create_index_with_invalid_primary_key() { #[actix_rt::test] async fn test_create_multiple_indexes() { - let server = Server::new().await; + let server = Server::new_shared(); let index1 = server.unique_index(); let index2 = server.unique_index(); let index3 = server.unique_index(); @@ -174,7 +174,7 @@ async fn test_create_multiple_indexes() { #[actix_rt::test] async fn error_create_existing_index() { - let server = Server::new().await; + let server = Server::new_shared(); let index = server.unique_index(); let (_, code) = index.create(Some("primary")).await; From 5b04189f7a37ad6f6c5bc8a153d6d177fa498b7f Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 7 Oct 2024 16:50:57 +0200 Subject: [PATCH 7/9] remove flaky assert --- meilisearch/tests/index/create_index.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/meilisearch/tests/index/create_index.rs b/meilisearch/tests/index/create_index.rs index 110690638..9b9fbd039 100644 --- a/meilisearch/tests/index/create_index.rs +++ b/meilisearch/tests/index/create_index.rs @@ -68,7 +68,6 @@ async fn create_index_with_gzip_encoded_request_and_receiving_brotli_encoded_res let parsed_response = serde_json::from_slice::(decoded.into().as_ref()).expect("Expecting valid json"); - assert_eq!(parsed_response["taskUid"], 3); assert_eq!(parsed_response["indexUid"], "test"); } From 6af55b1a80fb1d0f988232d82f90dca14d3ede76 Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 8 Oct 2024 11:59:43 +0200 Subject: [PATCH 8/9] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 84d1da8f5..20f4c27c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,7 @@ RUN set -eux; \ # Run FROM alpine:3.20 +LABEL org.opencontainers.image.source="https://github.com/meilisearch/meilisearch" ENV MEILI_HTTP_ADDR 0.0.0.0:7700 ENV MEILI_SERVER_PROVIDER docker From ed267fa0634b0306b96ccfa8c724c6b7a7d02645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine?= Date: Tue, 8 Oct 2024 14:14:16 +0200 Subject: [PATCH 9/9] Apply suggestions from code review --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 20f4c27c7..04557df59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN set -eux; \ # Run FROM alpine:3.20 -LABEL org.opencontainers.image.source="https://github.com/meilisearch/meilisearch" +LABEL org.opencontainers.image.source="https://github.com/meilisearch/meilisearch" ENV MEILI_HTTP_ADDR 0.0.0.0:7700 ENV MEILI_SERVER_PROVIDER docker