From 91c7ef8723f71941871bd4155c0b6568b3ebfce8 Mon Sep 17 00:00:00 2001 From: Mahmoud Rawas Date: Sat, 21 Dec 2024 21:46:51 +1100 Subject: [PATCH] #4840 - Partial fix - Remove hard coded task ids to prevent flaky tests. # Conflicts: # crates/meilisearch/tests/documents/add_documents.rs # crates/meilisearch/tests/search/facet_search.rs # crates/meilisearch/tests/settings/get_settings.rs # crates/meilisearch/tests/snapshot/mod.rs --- crates/meilisearch/tests/auth/tenant_token.rs | 12 +- .../tests/auth/tenant_token_multi_search.rs | 64 +++---- crates/meilisearch/tests/batches/mod.rs | 137 +++++++-------- .../tests/documents/add_documents.rs | 123 ++++++------- .../tests/documents/delete_documents.rs | 71 ++++---- crates/meilisearch/tests/index/get_index.rs | 8 +- crates/meilisearch/tests/index/stats.rs | 6 +- .../meilisearch/tests/index/update_index.rs | 24 +-- crates/meilisearch/tests/search/distinct.rs | 8 +- .../meilisearch/tests/search/facet_search.rs | 32 ++-- crates/meilisearch/tests/search/geo.rs | 4 +- crates/meilisearch/tests/search/locales.rs | 56 +++--- .../tests/search/matching_strategy.rs | 4 +- crates/meilisearch/tests/search/mod.rs | 85 ++++----- crates/meilisearch/tests/search/multi.rs | 156 ++++++++--------- .../tests/search/restrict_searchable.rs | 19 +- crates/meilisearch/tests/settings/distinct.rs | 16 +- .../tests/settings/get_settings.rs | 38 ++-- .../tests/settings/proximity_settings.rs | 32 ++-- .../tests/settings/tokenizer_customization.rs | 27 +-- crates/meilisearch/tests/snapshot/mod.rs | 4 +- crates/meilisearch/tests/stats/mod.rs | 6 +- crates/meilisearch/tests/swap_indexes/mod.rs | 8 +- crates/meilisearch/tests/tasks/mod.rs | 162 +++++++++--------- 24 files changed, 555 insertions(+), 547 deletions(-) diff --git a/crates/meilisearch/tests/auth/tenant_token.rs b/crates/meilisearch/tests/auth/tenant_token.rs index 2e3b228d3..808d5247f 100644 --- a/crates/meilisearch/tests/auth/tenant_token.rs +++ b/crates/meilisearch/tests/auth/tenant_token.rs @@ -99,12 +99,12 @@ macro_rules! compute_authorized_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - index + let (task1,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task1.uid()).await; + let (task2,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task2.uid()).await; drop(index); for key_content in ACCEPTED_KEYS.iter() { @@ -146,8 +146,8 @@ macro_rules! compute_forbidden_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; drop(index); for key_content in $parent_keys.iter() { diff --git a/crates/meilisearch/tests/auth/tenant_token_multi_search.rs b/crates/meilisearch/tests/auth/tenant_token_multi_search.rs index e994aa3bc..36a5fe9e4 100644 --- a/crates/meilisearch/tests/auth/tenant_token_multi_search.rs +++ b/crates/meilisearch/tests/auth/tenant_token_multi_search.rs @@ -267,22 +267,22 @@ macro_rules! compute_authorized_single_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - index + let (add_task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(add_task.uid()).await; + let (update_task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await; drop(index); let index = server.index("products"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; - index + let (add_task2,_status_code) = index.add_documents(documents, None).await; + index.wait_task(add_task2.uid()).await; + let (update_task2,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(update_task2.uid()).await; drop(index); @@ -338,22 +338,22 @@ macro_rules! compute_authorized_multiple_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; drop(index); let index = server.index("products"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await; drop(index); @@ -422,22 +422,22 @@ macro_rules! compute_forbidden_single_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; drop(index); let index = server.index("products"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await; drop(index); assert_eq!($parent_keys.len(), $failed_query_indexes.len(), "keys != query_indexes"); @@ -498,22 +498,22 @@ macro_rules! compute_forbidden_multiple_search { server.use_admin_key("MASTER_KEY").await; let index = server.index("sales"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; drop(index); let index = server.index("products"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; - index + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await; drop(index); assert_eq!($parent_keys.len(), $failed_query_indexes.len(), "keys != query_indexes"); diff --git a/crates/meilisearch/tests/batches/mod.rs b/crates/meilisearch/tests/batches/mod.rs index 49b83360b..940a64b35 100644 --- a/crates/meilisearch/tests/batches/mod.rs +++ b/crates/meilisearch/tests/batches/mod.rs @@ -1,5 +1,6 @@ mod errors; +use byte_unit::rust_decimal::prelude::ToPrimitive; use meili_snap::insta::assert_json_snapshot; use meili_snap::snapshot; @@ -10,8 +11,8 @@ use crate::json; async fn error_get_unexisting_batch_status() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_coder) = index.create(None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_batch(1).await; let expected_response = json!({ @@ -29,8 +30,8 @@ async fn error_get_unexisting_batch_status() { async fn get_batch_status() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await; let (_response, code) = index.get_batch(0).await; assert_eq!(code, 200); } @@ -39,8 +40,8 @@ async fn get_batch_status() { async fn list_batches() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -141,9 +142,9 @@ async fn list_batches_with_star_filters() { async fn list_batches_status_filtered() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; - index + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -156,7 +157,7 @@ async fn list_batches_status_filtered() { // assert_eq!(code, 200, "{}", response); // assert_eq!(response["results"].as_array().unwrap().len(), 1); - index.wait_task(1).await; + index.wait_task(task.uid()).await; let (response, code) = index.filtered_batches(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); @@ -167,17 +168,18 @@ async fn list_batches_status_filtered() { async fn list_batches_type_filtered() { let server = Server::new().await; let index = server.index("test"); - let (task, _) = index.create(None).await; - index.wait_task(task.uid()).await.succeeded(); - let (task, _) = index.delete().await; - index.wait_task(task.uid()).await.succeeded(); + let (task,_status_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; let (response, code) = index.filtered_batches(&["indexCreation"], &[], &[]).await; assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 1); let (response, code) = - index.filtered_batches(&["indexCreation", "indexDeletion"], &[], &[]).await; + index.filtered_batches(&["indexCreation", "documentAdditionOrUpdate"], &[], &[]).await; assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 2); } @@ -186,8 +188,8 @@ async fn list_batches_type_filtered() { async fn list_batches_invalid_canceled_by_filter() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -201,8 +203,8 @@ async fn list_batches_invalid_canceled_by_filter() { async fn list_batches_status_and_type_filtered() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -275,8 +277,8 @@ async fn list_batch_filter_error() { async fn test_summarized_document_addition_or_update() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), None).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -306,8 +308,8 @@ async fn test_summarized_document_addition_or_update() { } "#); - index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -342,8 +344,8 @@ async fn test_summarized_document_addition_or_update() { async fn test_summarized_delete_documents_by_batch() { let server = Server::new().await; let index = server.index("test"); - index.delete_batch(vec![1, 2, 3]).await; - index.wait_task(0).await; + let (task,_status_code) = index.delete_batch(vec![1, 2, 3]).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -374,8 +376,8 @@ async fn test_summarized_delete_documents_by_batch() { "#); index.create(None).await; - index.delete_batch(vec![42]).await; - index.wait_task(2).await; + let (task,_status_code) = index.delete_batch(vec![42]).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -411,8 +413,8 @@ async fn test_summarized_delete_documents_by_filter() { let server = Server::new().await; let index = server.index("test"); - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(0).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -444,8 +446,8 @@ async fn test_summarized_delete_documents_by_filter() { "#); index.create(None).await; - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(2).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -477,8 +479,8 @@ async fn test_summarized_delete_documents_by_filter() { "#); index.update_settings(json!({ "filterableAttributes": ["doggo"] })).await; - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(4).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(4).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -514,8 +516,8 @@ async fn test_summarized_delete_documents_by_filter() { async fn test_summarized_delete_document_by_id() { let server = Server::new().await; let index = server.index("test"); - index.delete_document(1).await; - index.wait_task(0).await; + let (task,_status_code) = index.delete_document(1).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -546,8 +548,8 @@ async fn test_summarized_delete_document_by_id() { "#); index.create(None).await; - index.delete_document(42).await; - index.wait_task(2).await; + let (task,_status_code) = index.delete_document(42).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -594,8 +596,8 @@ async fn test_summarized_settings_update() { } "###); - index.update_settings(json!({ "displayedAttributes": ["doggos", "name"], "filterableAttributes": ["age", "nb_paw_pads"], "sortableAttributes": ["iq"] })).await; - index.wait_task(0).await; + let (task,_status_code) = index.update_settings(json!({ "displayedAttributes": ["doggos", "name"], "filterableAttributes": ["age", "nb_paw_pads"], "sortableAttributes": ["iq"] })).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -639,8 +641,8 @@ async fn test_summarized_settings_update() { async fn test_summarized_index_creation() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -667,8 +669,8 @@ async fn test_summarized_index_creation() { } "#); - index.create(Some("doggos")).await; - index.wait_task(1).await; + let (task,_status_code) = index.create(Some("doggos")).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -812,8 +814,8 @@ async fn test_summarized_index_update() { let server = Server::new().await; let index = server.index("test"); // If the index doesn't exist yet, we should get errors with or without the primary key. - index.update(None).await; - index.wait_task(0).await; + let (task,_status_code) = index.update(None).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -840,8 +842,8 @@ async fn test_summarized_index_update() { } "#); - index.update(Some("bones")).await; - index.wait_task(1).await; + let (task,_status_code) = index.update(Some("bones")).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -873,8 +875,8 @@ async fn test_summarized_index_update() { // And run the same two tests once the index do exists. index.create(None).await; - index.update(None).await; - index.wait_task(3).await; + let (task,_status_code) = index.update(None).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(3).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -901,8 +903,8 @@ async fn test_summarized_index_update() { } "#); - index.update(Some("bones")).await; - index.wait_task(4).await; + let (task,_status_code) = index.update(Some("bones")).await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(4).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -935,12 +937,12 @@ async fn test_summarized_index_update() { #[actix_web::test] async fn test_summarized_index_swap() { let server = Server::new().await; - server + let (task,_status_code) = server .index_swap(json!([ { "indexes": ["doggos", "cattos"] } ])) .await; - server.wait_task(0).await; + server.wait_task(task.uid()).await; let (batch, _) = server.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -975,14 +977,14 @@ async fn test_summarized_index_swap() { "#); server.index("doggos").create(None).await; - server.index("cattos").create(None).await; + let (task,_status_code) = server.index("cattos").create(None).await; server .index_swap(json!([ { "indexes": ["doggos", "cattos"] } ])) .await; - server.wait_task(3).await; - let (batch, _) = server.get_batch(3).await; + server.wait_task(task.uid()).await; + let (batch, _) = server.get_batch(task.uid().to_u32().unwrap()).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r#" @@ -1021,11 +1023,12 @@ async fn test_summarized_batch_cancelation() { let server = Server::new().await; let index = server.index("doggos"); // to avoid being flaky we're only going to cancel an already finished batch :( - index.create(None).await; - index.wait_task(0).await; - server.cancel_tasks("uids=0").await; - index.wait_task(1).await; - let (batch, _) = index.get_batch(1).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = server.cancel_tasks("uids=0").await; + index.wait_task(task.uid()).await; + //TODO: create a get_batch function interface that accepts u64, and remove the following cast. + let (batch, _) = index.get_batch(task.uid().to_u32().unwrap()).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r#" @@ -1059,10 +1062,10 @@ async fn test_summarized_batch_deletion() { let server = Server::new().await; let index = server.index("doggos"); // to avoid being flaky we're only going to delete an already finished batch :( - index.create(None).await; - index.wait_task(0).await; - server.delete_tasks("uids=0").await; - index.wait_task(1).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = server.delete_tasks("uids=0").await; + index.wait_task(task.uid()).await; let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -1095,8 +1098,8 @@ async fn test_summarized_batch_deletion() { #[actix_web::test] async fn test_summarized_dump_creation() { let server = Server::new().await; - server.create_dump().await; - server.wait_task(0).await; + let (task,_status_code) = server.create_dump().await; + server.wait_task(task.uid()).await; let (batch, _) = server.get_batch(0).await; assert_json_snapshot!(batch, { ".details.dumpUid" => "[dumpUid]", ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, diff --git a/crates/meilisearch/tests/documents/add_documents.rs b/crates/meilisearch/tests/documents/add_documents.rs index d72b1a7a8..2cdc7c0a6 100644 --- a/crates/meilisearch/tests/documents/add_documents.rs +++ b/crates/meilisearch/tests/documents/add_documents.rs @@ -1,4 +1,5 @@ use actix_web::test; +use actix_web::web::resource; use meili_snap::{json_string, snapshot}; use meilisearch::Opt; use time::format_description::well_known::Rfc3339; @@ -980,7 +981,7 @@ async fn add_documents_no_index_creation() { snapshot!(code, @"202 Accepted"); assert_eq!(response["taskUid"], 0); - index.wait_task(0).await; + index.wait_task(response.uid()).await; let (response, code) = index.get_task(0).await; snapshot!(code, @"200 OK"); @@ -1059,9 +1060,9 @@ async fn document_addition_with_primary_key() { } "###); - index.wait_task(0).await; + index.wait_task(response.uid()).await; - let (response, code) = index.get_task(0).await; + let (response, code) = index.get_task(response.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1169,7 +1170,7 @@ async fn replace_document() { } "###); - index.wait_task(0).await; + index.wait_task(response.uid()).await; let documents = json!([ { @@ -1178,12 +1179,12 @@ async fn replace_document() { } ]); - let (_response, code) = index.add_documents(documents, None).await; + let (task, code) = index.add_documents(documents, None).await; snapshot!(code,@"202 Accepted"); - index.wait_task(1).await; + index.wait_task(task.uid()).await; - let (response, code) = index.get_task(1).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1273,9 +1274,9 @@ async fn error_add_documents_bad_document_id() { "content": "foobar" } ]); - let (value, _code) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; - let (response, code) = index.get_task(value.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(1).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1389,8 +1390,8 @@ async fn error_add_documents_missing_document_id() { "content": "foobar" } ]); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(1).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1701,8 +1702,8 @@ async fn add_documents_with_geo_field() { }, ]); - index.add_documents(documents, None).await; - let response = index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + let response = index.wait_task(task.uid()).await; snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" { @@ -1740,8 +1741,8 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(2).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1778,8 +1779,8 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(3).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(3).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1816,8 +1817,8 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(4).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(4).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1854,9 +1855,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(5).await; - let (response, code) = index.get_task(5).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1892,9 +1893,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(6).await; - let (response, code) = index.get_task(6).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1930,9 +1931,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(7).await; - let (response, code) = index.get_task(7).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -1968,9 +1969,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(8).await; - let (response, code) = index.get_task(8).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2006,9 +2007,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(9).await; - let (response, code) = index.get_task(9).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2044,9 +2045,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(10).await; - let (response, code) = index.get_task(10).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2082,9 +2083,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(11).await; - let (response, code) = index.get_task(11).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2120,9 +2121,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(12).await; - let (response, code) = index.get_task(12).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2158,9 +2159,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(13).await; - let (response, code) = index.get_task(13).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" @@ -2408,8 +2409,8 @@ async fn error_primary_key_inference() { } ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(0).await; assert_eq!(code, 200); @@ -2449,9 +2450,9 @@ async fn error_primary_key_inference() { } ]); - index.add_documents(documents, None).await; - index.wait_task(1).await; - let (response, code) = index.get_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; assert_eq!(code, 200); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -2488,9 +2489,9 @@ async fn error_primary_key_inference() { } ]); - index.add_documents(documents, None).await; - index.wait_task(2).await; - let (response, code) = index.get_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; + let (response, code) = index.get_task(task.uid()).await; assert_eq!(code, 200); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -2527,14 +2528,14 @@ async fn add_documents_with_primary_key_twice() { } ]); - index.add_documents(documents.clone(), Some("title")).await; - index.wait_task(0).await; - let (response, _code) = index.get_task(0).await; + let (task,_status_code) = index.add_documents(documents.clone(), Some("title")).await; + index.wait_task(task.uid()).await; + let (response, _code) = index.get_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); - index.add_documents(documents, Some("title")).await; - index.wait_task(1).await; - let (response, _code) = index.get_task(1).await; + let (task,_status_code) = index.add_documents(documents, Some("title")).await; + index.wait_task(task.uid()).await; + let (response, _code) = index.get_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); } diff --git a/crates/meilisearch/tests/documents/delete_documents.rs b/crates/meilisearch/tests/documents/delete_documents.rs index c50823183..d17082c81 100644 --- a/crates/meilisearch/tests/documents/delete_documents.rs +++ b/crates/meilisearch/tests/documents/delete_documents.rs @@ -7,10 +7,10 @@ use crate::json; async fn delete_one_document_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_response, code) = index.delete_document(0).await; + let (task, code) = index.delete_document(0).await; assert_eq!(code, 202); - let response = index.wait_task(0).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "failed"); } @@ -22,7 +22,7 @@ async fn delete_one_unexisting_document() { index.create(None).await; let (response, code) = index.delete_document(0).await; assert_eq!(code, 202, "{}", response); - let update = index.wait_task(0).await; + let update = index.wait_task(response.uid()).await; assert_eq!(update["status"], "succeeded"); } @@ -30,11 +30,11 @@ async fn delete_one_unexisting_document() { async fn delete_one_document() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(json!([{ "id": 0, "content": "foobar" }]), None).await; - index.wait_task(0).await; - let (_response, code) = server.index("test").delete_document(0).await; - assert_eq!(code, 202); - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(json!([{ "id": 0, "content": "foobar" }]), None).await; + index.wait_task(task.uid()).await; + let (task,status_code) = server.index("test").delete_document(0).await; + assert_eq!(status_code, 202); + index.wait_task(task.uid()).await; let (_response, code) = index.get_document(0, None).await; assert_eq!(code, 404); @@ -44,10 +44,10 @@ async fn delete_one_document() { async fn clear_all_documents_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_response, code) = index.clear_all_documents().await; + let (task, code) = index.clear_all_documents().await; assert_eq!(code, 202); - let response = index.wait_task(0).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "failed"); } @@ -56,17 +56,17 @@ async fn clear_all_documents_unexisting_index() { async fn clear_all_documents() { let server = Server::new().await; let index = server.index("test"); - index + let (task,_status_code) = index .add_documents( json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }]), None, ) .await; - index.wait_task(0).await; - let (_response, code) = index.clear_all_documents().await; + index.wait_task(task.uid()).await; + let (task, code) = index.clear_all_documents().await; assert_eq!(code, 202); - let _update = index.wait_task(1).await; + let _update = index.wait_task(task.uid()).await; let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; assert_eq!(code, 200); assert!(response["results"].as_array().unwrap().is_empty()); @@ -76,13 +76,14 @@ async fn clear_all_documents() { async fn clear_all_documents_empty_index() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - - let (_response, code) = index.clear_all_documents().await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task, code) = index.clear_all_documents().await; assert_eq!(code, 202); - let _update = index.wait_task(0).await; + let _update = index.wait_task(task.uid()).await; let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + index.wait_task(response.uid()).await; assert_eq!(code, 200); assert!(response["results"].as_array().unwrap().is_empty()); } @@ -91,7 +92,7 @@ async fn clear_all_documents_empty_index() { async fn error_delete_batch_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.delete_batch(vec![]).await; + let (task, code) = index.delete_batch(vec![]).await; let expected_response = json!({ "message": "Index `test` not found.", "code": "index_not_found", @@ -100,7 +101,7 @@ async fn error_delete_batch_unexisting_index() { }); assert_eq!(code, 202); - 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); @@ -110,12 +111,12 @@ async fn error_delete_batch_unexisting_index() { async fn delete_batch() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await; - index.wait_task(0).await; - let (_response, code) = index.delete_batch(vec![1, 0]).await; + let (task,_status_code) = index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await; + index.wait_task(task.uid()).await; + let (task, code) = index.delete_batch(vec![1, 0]).await; assert_eq!(code, 202); - let _update = index.wait_task(1).await; + let _update = index.wait_task(task.uid()).await; let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; assert_eq!(code, 200); assert_eq!(response["results"].as_array().unwrap().len(), 1); @@ -126,12 +127,12 @@ async fn delete_batch() { async fn delete_no_document_batch() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(json!([{ "id": 1, "content": "foobar" }, { "id": 0, "content": "foobar" }, { "id": 3, "content": "foobar" }]), Some("id")).await; + index.wait_task(task.uid()).await; let (_response, code) = index.delete_batch(vec![]).await; assert_eq!(code, 202, "{}", _response); - let _update = index.wait_task(1).await; + let _update = index.wait_task(_response.uid()).await; let (response, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; assert_eq!(code, 200); assert_eq!(response["results"].as_array().unwrap().len(), 3); @@ -142,7 +143,7 @@ async fn delete_document_by_filter() { let server = Server::new().await; let index = server.index("doggo"); index.update_settings_filterable_attributes(json!(["color"])).await; - index + let (task,_status_code) = index .add_documents( json!([ { "id": 0, "color": "red" }, @@ -153,7 +154,7 @@ async fn delete_document_by_filter() { Some("id"), ) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; let (stats, _) = index.stats().await; snapshot!(json_string!(stats), @r###" @@ -180,7 +181,7 @@ async fn delete_document_by_filter() { } "###); - let response = index.wait_task(2).await; + let response = index.wait_task(response.uid()).await; snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" { "uid": 2, @@ -246,7 +247,7 @@ async fn delete_document_by_filter() { } "###); - let response = index.wait_task(3).await; + let response = index.wait_task(response.uid()).await; snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" { "uid": 3, @@ -302,7 +303,7 @@ async fn delete_document_by_complex_filter() { let server = Server::new().await; let index = server.index("doggo"); index.update_settings_filterable_attributes(json!(["color"])).await; - index + let (task,_status_code) = index .add_documents( json!([ { "id": 0, "color": "red" }, @@ -314,7 +315,7 @@ async fn delete_document_by_complex_filter() { Some("id"), ) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; let (response, code) = index .delete_document_by_filter( json!({ "filter": ["color != red", "color != green", "color EXISTS"] }), @@ -331,7 +332,7 @@ async fn delete_document_by_complex_filter() { } "###); - let response = index.wait_task(2).await; + let response = index.wait_task(response.uid()).await; snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" { "uid": 2, @@ -390,7 +391,7 @@ async fn delete_document_by_complex_filter() { } "###); - let response = index.wait_task(3).await; + let response = index.wait_task(response.uid()).await; snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" { "uid": 3, diff --git a/crates/meilisearch/tests/index/get_index.rs b/crates/meilisearch/tests/index/get_index.rs index ce08251be..e22874b81 100644 --- a/crates/meilisearch/tests/index/get_index.rs +++ b/crates/meilisearch/tests/index/get_index.rs @@ -7,11 +7,11 @@ use crate::common::Server; async fn create_and_get_index() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.create(None).await; + let (task, code) = index.create(None).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(task.uid()).await; let (response, code) = index.get().await; @@ -55,9 +55,9 @@ async fn no_index_return_empty_list() { async fn list_multiple_indexes() { let server = Server::new().await; server.index("test").create(None).await; - server.index("test1").create(Some("key")).await; + let (task,_status_code) = server.index("test1").create(Some("key")).await; - server.index("test").wait_task(1).await; + server.index("test").wait_task(task.uid()).await; let (response, code) = server.list_indexes(None, None).await; assert_eq!(code, 200); diff --git a/crates/meilisearch/tests/index/stats.rs b/crates/meilisearch/tests/index/stats.rs index d0b0a56b9..c427af12d 100644 --- a/crates/meilisearch/tests/index/stats.rs +++ b/crates/meilisearch/tests/index/stats.rs @@ -5,11 +5,11 @@ use crate::json; async fn stats() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.create(Some("id")).await; + let (task, code) = index.create(Some("id")).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(task.uid()).await; let (response, code) = index.stats().await; @@ -33,7 +33,7 @@ async fn stats() { assert_eq!(code, 202); assert_eq!(response["taskUid"], 1); - index.wait_task(1).await; + index.wait_task(response.uid()).await; let (response, code) = index.stats().await; diff --git a/crates/meilisearch/tests/index/update_index.rs b/crates/meilisearch/tests/index/update_index.rs index f991c3580..d00a44564 100644 --- a/crates/meilisearch/tests/index/update_index.rs +++ b/crates/meilisearch/tests/index/update_index.rs @@ -13,9 +13,9 @@ async fn update_primary_key() { assert_eq!(code, 202); - index.update(Some("primary")).await; + let (task,_status_code) = index.update(Some("primary")).await; - let response = index.wait_task(1).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); @@ -46,9 +46,9 @@ async fn create_and_update_with_different_encoding() { assert_eq!(code, 202); let index = server.index_with_encoder("test", Encoder::Brotli); - index.update(Some("primary")).await; + let (task,_status_code) = index.update(Some("primary")).await; - let response = index.wait_task(1).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); } @@ -57,17 +57,17 @@ async fn create_and_update_with_different_encoding() { async fn update_nothing() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.create(None).await; + let (task1, code) = index.create(None).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(task1.uid()).await; - let (_, code) = index.update(None).await; + let (task2, code) = index.update(None).await; assert_eq!(code, 202); - let response = index.wait_task(1).await; + let response = index.wait_task(task2.uid()).await; assert_eq!(response["status"], "succeeded"); } @@ -88,11 +88,11 @@ async fn error_update_existing_primary_key() { ]); index.add_documents(documents, None).await; - let (_, code) = index.update(Some("primary")).await; + let (task, code) = index.update(Some("primary")).await; assert_eq!(code, 202); - let response = index.wait_task(2).await; + let response = index.wait_task(task.uid()).await; let expected_response = json!({ "message": "Index `test`: Index already has a primary key: `id`.", @@ -107,11 +107,11 @@ async fn error_update_existing_primary_key() { #[actix_rt::test] async fn error_update_unexisting_index() { let server = Server::new().await; - let (_, code) = server.index("test").update(None).await; + let (task, code) = server.index("test").update(None).await; assert_eq!(code, 202); - let response = server.index("test").wait_task(0).await; + let response = server.index("test").wait_task(task.uid()).await; let expected_response = json!({ "message": "Index `test` not found.", diff --git a/crates/meilisearch/tests/search/distinct.rs b/crates/meilisearch/tests/search/distinct.rs index 2023c01a8..b488c35a2 100644 --- a/crates/meilisearch/tests/search/distinct.rs +++ b/crates/meilisearch/tests/search/distinct.rs @@ -151,8 +151,8 @@ async fn distinct_search_with_offset_no_ranking() { let documents = DOCUMENTS.clone(); index.add_documents(documents, Some(DOCUMENT_PRIMARY_KEY)).await; - index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await; + index.wait_task(task.uid()).await; fn get_hits(response: &Value) -> Vec<&str> { let hits_array = response["hits"].as_array().unwrap(); @@ -210,8 +210,8 @@ async fn distinct_search_with_pagination_no_ranking() { let documents = DOCUMENTS.clone(); index.add_documents(documents, Some(DOCUMENT_PRIMARY_KEY)).await; - index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_distinct_attribute(json!(DOCUMENT_DISTINCT_KEY)).await; + index.wait_task(task.uid()).await; fn get_hits(response: &Value) -> Vec<&str> { let hits_array = response["hits"].as_array().unwrap(); diff --git a/crates/meilisearch/tests/search/facet_search.rs b/crates/meilisearch/tests/search/facet_search.rs index 696c23f91..56afc35e7 100644 --- a/crates/meilisearch/tests/search/facet_search.rs +++ b/crates/meilisearch/tests/search/facet_search.rs @@ -41,8 +41,8 @@ async fn simple_facet_search() { let documents = DOCUMENTS.clone(); index.update_settings_filterable_attributes(json!(["genres"])).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; @@ -175,8 +175,8 @@ async fn advanced_facet_search() { let documents = DOCUMENTS.clone(); index.update_settings_filterable_attributes(json!(["genres"])).await; index.update_settings_typo_tolerance(json!({ "enabled": false })).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "adventre"})).await; @@ -199,8 +199,8 @@ async fn more_advanced_facet_search() { let documents = DOCUMENTS.clone(); index.update_settings_filterable_attributes(json!(["genres"])).await; index.update_settings_typo_tolerance(json!({ "disableOnWords": ["adventre"] })).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "adventre"})).await; @@ -223,8 +223,8 @@ async fn simple_facet_search_with_max_values() { let documents = DOCUMENTS.clone(); index.update_settings_faceting(json!({ "maxValuesPerFacet": 1 })).await; index.update_settings_filterable_attributes(json!(["genres"])).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; @@ -245,8 +245,8 @@ async fn simple_facet_search_by_count_with_max_values() { ) .await; index.update_settings_filterable_attributes(json!(["genres"])).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; @@ -261,8 +261,8 @@ async fn non_filterable_facet_search_error() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; @@ -280,8 +280,8 @@ async fn facet_search_dont_support_words() { let documents = DOCUMENTS.clone(); index.update_settings_filterable_attributes(json!(["genres"])).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "words"})).await; @@ -298,8 +298,8 @@ async fn simple_facet_search_with_sort_by_count() { let documents = DOCUMENTS.clone(); index.update_settings_faceting(json!({ "sortFacetValuesBy": { "*": "count" } })).await; index.update_settings_filterable_attributes(json!(["genres"])).await; - let (response, _code) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; diff --git a/crates/meilisearch/tests/search/geo.rs b/crates/meilisearch/tests/search/geo.rs index e92056191..0af88a699 100644 --- a/crates/meilisearch/tests/search/geo.rs +++ b/crates/meilisearch/tests/search/geo.rs @@ -46,8 +46,8 @@ async fn geo_sort_with_geo_strings() { let documents = DOCUMENTS.clone(); index.update_settings_filterable_attributes(json!(["_geo"])).await; index.update_settings_sortable_attributes(json!(["_geo"])).await; - index.add_documents(documents, None).await; - index.wait_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search( diff --git a/crates/meilisearch/tests/search/locales.rs b/crates/meilisearch/tests/search/locales.rs index c01d854e2..345c52193 100644 --- a/crates/meilisearch/tests/search/locales.rs +++ b/crates/meilisearch/tests/search/locales.rs @@ -98,8 +98,8 @@ async fn simple_search() { json!({"searchableAttributes": ["name_en", "name_ja", "name_zh", "author_en", "author_ja", "author_zh", "description_en", "description_ja", "description_zh"]}), ) .await; - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // english index @@ -220,8 +220,8 @@ async fn force_locales() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // chinese detection index @@ -298,8 +298,8 @@ async fn force_locales_with_pattern() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // chinese detection index @@ -374,8 +374,8 @@ async fn force_locales_with_pattern_nested() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // chinese index @@ -449,8 +449,8 @@ async fn force_different_locales_with_pattern() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // force chinese index @@ -527,8 +527,8 @@ async fn auto_infer_locales_at_search_with_attributes_to_search_on() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // auto infer any language index @@ -601,8 +601,8 @@ async fn auto_infer_locales_at_search() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search( @@ -700,8 +700,8 @@ async fn force_different_locales_with_pattern_nested() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; // chinese index @@ -778,8 +778,8 @@ async fn settings_change() { let index = server.index("test"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, _) = index .update_settings(json!({ "searchableAttributes": ["document_en", "document_ja", "document_zh"], @@ -798,7 +798,7 @@ async fn settings_change() { "enqueuedAt": "[date]" } "###); - index.wait_task(1).await; + index.wait_task(response.uid()).await; // chinese index @@ -861,7 +861,7 @@ async fn settings_change() { "enqueuedAt": "[date]" } "###); - index.wait_task(2).await; + index.wait_task(response.uid()).await; // chinese index @@ -915,8 +915,8 @@ async fn invalid_locales() { json!({"searchableAttributes": ["name_en", "name_ja", "name_zh", "author_en", "author_ja", "author_zh", "description_en", "description_ja", "description_zh"]}), ) .await; - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.search_post(json!({"q": "Atta", "locales": ["invalid"]})).await; snapshot!(code, @"400 Bad Request"); @@ -1033,8 +1033,8 @@ async fn simple_facet_search() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, _) = index .facet_search(json!({"facetName": "name_zh", "facetQuery": "進撃", "locales": ["cmn"]})) @@ -1095,8 +1095,8 @@ async fn facet_search_with_localized_attributes() { "enqueuedAt": "[date]" } "###); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, _) = index .facet_search(json!({"facetName": "name_zh", "facetQuery": "进击", "locales": ["cmn"]})) @@ -1165,7 +1165,7 @@ async fn swedish_search() { ] })) .await; - index.wait_task(1).await; + index.wait_task(_response.uid()).await; // infer swedish index @@ -1286,7 +1286,7 @@ async fn german_search() { ] })) .await; - index.wait_task(1).await; + index.wait_task(_response.uid()).await; // infer swedish index diff --git a/crates/meilisearch/tests/search/matching_strategy.rs b/crates/meilisearch/tests/search/matching_strategy.rs index a4cb19f62..83334703a 100644 --- a/crates/meilisearch/tests/search/matching_strategy.rs +++ b/crates/meilisearch/tests/search/matching_strategy.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,_status_code) =index.add_documents(documents.clone(), None).await; + index.wait_task(task.uid()).await; index } diff --git a/crates/meilisearch/tests/search/mod.rs b/crates/meilisearch/tests/search/mod.rs index 057b2b3a2..8ccd7f1df 100644 --- a/crates/meilisearch/tests/search/mod.rs +++ b/crates/meilisearch/tests/search/mod.rs @@ -138,8 +138,8 @@ async fn phrase_search_with_stop_word() { meili_snap::snapshot!(code, @"202 Accepted"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "how \"to\" train \"the" }), |response, code| { @@ -218,11 +218,11 @@ async fn negative_special_cases_search() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; - index.update_settings(json!({"synonyms": { "escape": ["gläss"] }})).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings(json!({"synonyms": { "escape": ["gläss"] }})).await; + index.wait_task(task.uid()).await; // There is a synonym for escape -> glass but we don't want "escape", only the derivates: glass index @@ -247,8 +247,8 @@ async fn test_kanji_language_detection() { { "id": 1, "title": "東京のお寿司。" }, { "id": 2, "title": "הַשּׁוּעָל הַמָּהִיר (״הַחוּם״) לֹא יָכוֹל לִקְפֹּץ 9.94 מֶטְרִים, נָכוֹן? ברר, 1.5°C- בַּחוּץ!" } ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "東京"}), |response, code| { @@ -270,11 +270,11 @@ async fn test_thai_language() { { "id": 1, "title": "สบู่สมุนไพรชาเขียว 100 กรัม จำนวน 6 ก้อน" }, { "id": 2, "title": "สบู่สมุนไพรฝางแดงผสมว่านหางจรเข้ 100 กรัม จำนวน 6 ก้อน" } ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; - index.update_settings(json!({"rankingRules": ["exactness"]})).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings(json!({"rankingRules": ["exactness"]})).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "สบู"}), |response, code| { @@ -329,9 +329,9 @@ async fn search_with_filter_string_notation() { meili_snap::snapshot!(code, @"202 Accepted"); let documents = DOCUMENTS.clone(); - let (_, code) = index.add_documents(documents, None).await; + let (task, code) = index.add_documents(documents, None).await; meili_snap::snapshot!(code, @"202 Accepted"); - let res = index.wait_task(1).await; + let res = index.wait_task(task.uid()).await; meili_snap::snapshot!(res["status"], @r###""succeeded""###); index @@ -353,9 +353,9 @@ async fn search_with_filter_string_notation() { meili_snap::snapshot!(code, @"202 Accepted"); let documents = NESTED_DOCUMENTS.clone(); - let (_, code) = index.add_documents(documents, None).await; + let (task, code) = index.add_documents(documents, None).await; meili_snap::snapshot!(code, @"202 Accepted"); - let res = index.wait_task(3).await; + let res = index.wait_task(task.uid()).await; meili_snap::snapshot!(res["status"], @r###""succeeded""###); index @@ -607,8 +607,8 @@ async fn displayed_attributes() { index.update_settings(json!({ "displayedAttributes": ["title"] })).await; let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = index.search_post(json!({ "attributesToRetrieve": ["title", "id"] })).await; @@ -622,8 +622,8 @@ async fn placeholder_search_is_hard_limited() { let index = server.index("test"); let documents: Vec<_> = (0..1200).map(|i| json!({ "id": i, "text": "I am unique!" })).collect(); - index.add_documents(documents.into(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents.into(), None).await; + index.wait_task(task.uid()).await; index .search( @@ -650,8 +650,8 @@ async fn placeholder_search_is_hard_limited() { ) .await; - index.update_settings(json!({ "pagination": { "maxTotalHits": 10_000 } })).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings(json!({ "pagination": { "maxTotalHits": 10_000 } })).await; + index.wait_task(task.uid()).await; index .search( @@ -685,8 +685,8 @@ async fn search_is_hard_limited() { let index = server.index("test"); let documents: Vec<_> = (0..1200).map(|i| json!({ "id": i, "text": "I am unique!" })).collect(); - index.add_documents(documents.into(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents.into(), None).await; + index.wait_task(task.uid()).await; index .search( @@ -715,8 +715,8 @@ async fn search_is_hard_limited() { ) .await; - index.update_settings(json!({ "pagination": { "maxTotalHits": 10_000 } })).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings(json!({ "pagination": { "maxTotalHits": 10_000 } })).await; + index.wait_task(task.uid()).await; index .search( @@ -754,8 +754,8 @@ async fn faceting_max_values_per_facet() { index.update_settings(json!({ "filterableAttributes": ["number"] })).await; let documents: Vec<_> = (0..10_000).map(|id| json!({ "id": id, "number": id * 10 })).collect(); - index.add_documents(json!(documents), None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(json!(documents), None).await; + index.wait_task(task.uid()).await; index .search( @@ -770,8 +770,8 @@ async fn faceting_max_values_per_facet() { ) .await; - index.update_settings(json!({ "faceting": { "maxValuesPerFacet": 10_000 } })).await; - index.wait_task(2).await; + let (task,_status_code) = index.update_settings(json!({ "faceting": { "maxValuesPerFacet": 10_000 } })).await; + index.wait_task(task.uid()).await; index .search( @@ -1162,8 +1162,8 @@ async fn experimental_feature_vector_store() { let documents = DOCUMENTS.clone(); - index.add_documents(json!(documents), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(json!(documents), None).await; + index.wait_task(task.uid()).await; let (response, code) = index .search_post(json!({ @@ -1369,8 +1369,8 @@ async fn camelcased_words() { { "id": 3, "title": "TestAb" }, { "id": 4, "title": "testab" }, ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "deLonghi"}), |response, code| { @@ -1587,13 +1587,13 @@ async fn simple_search_with_strange_synonyms() { let server = Server::new().await; let index = server.index("test"); - index.update_settings(json!({ "synonyms": {"&": ["to"], "to": ["&"]} })).await; - let r = index.wait_task(0).await; + let (task,_status_code) = index.update_settings(json!({ "synonyms": {"&": ["to"], "to": ["&"]} })).await; + let r = index.wait_task(task.uid()).await; meili_snap::snapshot!(r["status"], @r###""succeeded""###); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "How to train"}), |response, code| { @@ -1679,11 +1679,12 @@ async fn change_attributes_settings() { index.update_settings(json!({ "searchableAttributes": ["father", "mother"] })).await; let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(json!(documents), None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(json!(documents), None).await; + index.wait_task(task.uid()).await; - index.update_settings(json!({ "searchableAttributes": ["father", "mother", "doggos"], "filterableAttributes": ["doggos"] })).await; - index.wait_task(2).await; + let (task,_status_code) = + index.update_settings(json!({ "searchableAttributes": ["father", "mother", "doggos"], "filterableAttributes": ["doggos"] })).await; + index.wait_task(task.uid()).await; // search index diff --git a/crates/meilisearch/tests/search/multi.rs b/crates/meilisearch/tests/search/multi.rs index 9377f435a..bf07914be 100644 --- a/crates/meilisearch/tests/search/multi.rs +++ b/crates/meilisearch/tests/search/multi.rs @@ -89,8 +89,8 @@ async fn simple_search_single_index() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -161,8 +161,8 @@ async fn federation_single_search_single_index() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -208,8 +208,8 @@ async fn federation_multiple_search_single_index() { let index = server.index("test"); let documents = SCORE_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -283,8 +283,8 @@ async fn federation_two_search_single_index() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -351,8 +351,8 @@ async fn simple_search_missing_index_uid() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -376,8 +376,8 @@ async fn federation_simple_search_missing_index_uid() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -401,8 +401,8 @@ async fn simple_search_illegal_index_uid() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -426,8 +426,8 @@ async fn federation_search_illegal_index_uid() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -451,13 +451,13 @@ async fn simple_search_two_indexes() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (add_task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(add_task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -558,13 +558,13 @@ async fn federation_two_search_two_indexes() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -666,18 +666,18 @@ async fn federation_multiple_search_multiple_indexes() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("score"); let documents = SCORE_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -924,8 +924,8 @@ async fn search_one_index_doesnt_exist() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -950,8 +950,8 @@ async fn federation_one_index_doesnt_exist() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -1021,13 +1021,13 @@ async fn search_one_query_error() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -1053,13 +1053,13 @@ async fn federation_one_query_error() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -1085,13 +1085,13 @@ async fn federation_one_query_sort_error() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -1117,13 +1117,13 @@ async fn search_multiple_query_errors() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -1149,13 +1149,13 @@ async fn federation_multiple_query_errors() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -1181,13 +1181,13 @@ async fn federation_multiple_query_sort_errors() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -1213,13 +1213,13 @@ async fn federation_multiple_query_errors_interleaved() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -1246,13 +1246,13 @@ async fn federation_multiple_query_sort_errors_interleaved() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let (response, code) = server .multi_search(json!({"queries": [ @@ -3020,18 +3020,18 @@ async fn federation_limit_offset() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("score"); let documents = SCORE_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; { let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -3338,18 +3338,18 @@ async fn federation_formatting() { let index = server.index("test"); let documents = DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("nested"); let documents = NESTED_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; let index = server.index("score"); let documents = SCORE_DOCUMENTS.clone(); - index.add_documents(documents, None).await; - index.wait_task(2).await; + let (task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await; { let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ diff --git a/crates/meilisearch/tests/search/restrict_searchable.rs b/crates/meilisearch/tests/search/restrict_searchable.rs index abd13fadf..37b2068b2 100644 --- a/crates/meilisearch/tests/search/restrict_searchable.rs +++ b/crates/meilisearch/tests/search/restrict_searchable.rs @@ -1,3 +1,4 @@ +use actix_web::web::resource; use meili_snap::{json_string, snapshot}; use once_cell::sync::Lazy; @@ -64,8 +65,8 @@ async fn search_no_searchable_attribute_set() { ) .await; - index.update_settings_searchable_attributes(json!(["*"])).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings_searchable_attributes(json!(["*"])).await; + index.wait_task(task.uid()).await; index .search( @@ -77,8 +78,8 @@ async fn search_no_searchable_attribute_set() { ) .await; - index.update_settings_searchable_attributes(json!(["*"])).await; - index.wait_task(2).await; + let (task,_status_code) = index.update_settings_searchable_attributes(json!(["*"])).await; + index.wait_task(task.uid()).await; index .search( @@ -108,8 +109,8 @@ async fn search_on_all_attributes() { async fn search_on_all_attributes_restricted_set() { let server = Server::new().await; let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await; - index.update_settings_searchable_attributes(json!(["title"])).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings_searchable_attributes(json!(["title"])).await; + index.wait_task(task.uid()).await; index .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["*"]}), |response, code| { @@ -191,8 +192,8 @@ async fn word_ranking_rule_order() { async fn word_ranking_rule_order_exact_words() { let server = Server::new().await; let index = index_with_documents(&server, &SIMPLE_SEARCH_DOCUMENTS).await; - index.update_settings_typo_tolerance(json!({"disableOnWords": ["Captain", "Marvel"]})).await; - index.wait_task(1).await; + let (task,_status_code) = index.update_settings_typo_tolerance(json!({"disableOnWords": ["Captain", "Marvel"]})).await; + index.wait_task(task.uid()).await; // simple search should return 2 documents (ids: 2 and 3). index @@ -358,7 +359,7 @@ async fn search_on_exact_field() { let (response, code) = index.update_settings_typo_tolerance(json!({ "disableOnAttributes": ["exact"] })).await; assert_eq!(202, code, "{:?}", response); - index.wait_task(1).await; + index.wait_task(response.uid()).await; // Searching on an exact attribute should only return the document matching without typo. index .search(json!({"q": "Marvel", "attributesToSearchOn": ["exact"]}), |response, code| { diff --git a/crates/meilisearch/tests/settings/distinct.rs b/crates/meilisearch/tests/settings/distinct.rs index 42c5d38bd..a1715360d 100644 --- a/crates/meilisearch/tests/settings/distinct.rs +++ b/crates/meilisearch/tests/settings/distinct.rs @@ -6,16 +6,16 @@ async fn set_and_reset_distinct_attribute() { let server = Server::new().await; let index = server.index("test"); - let (_response, _code) = index.update_settings(json!({ "distinctAttribute": "test"})).await; - index.wait_task(0).await; + let (task1, _code) = index.update_settings(json!({ "distinctAttribute": "test"})).await; + index.wait_task(task1.uid()).await; let (response, _) = index.settings().await; assert_eq!(response["distinctAttribute"], "test"); - index.update_settings(json!({ "distinctAttribute": null })).await; + let (task2,_status_code) = index.update_settings(json!({ "distinctAttribute": null })).await; - index.wait_task(1).await; + index.wait_task(task2.uid()).await; let (response, _) = index.settings().await; @@ -27,16 +27,16 @@ async fn set_and_reset_distinct_attribute_with_dedicated_route() { let server = Server::new().await; let index = server.index("test"); - let (_response, _code) = index.update_distinct_attribute(json!("test")).await; - index.wait_task(0).await; + let (update_task1, _code) = index.update_distinct_attribute(json!("test")).await; + index.wait_task(update_task1.uid()).await; let (response, _) = index.get_distinct_attribute().await; assert_eq!(response, "test"); - index.update_distinct_attribute(json!(null)).await; + let (update_task2,_status_code) = index.update_distinct_attribute(json!(null)).await; - index.wait_task(1).await; + index.wait_task(update_task2.uid()).await; let (response, _) = index.get_distinct_attribute().await; diff --git a/crates/meilisearch/tests/settings/get_settings.rs b/crates/meilisearch/tests/settings/get_settings.rs index 55d9441ee..f487ca204 100644 --- a/crates/meilisearch/tests/settings/get_settings.rs +++ b/crates/meilisearch/tests/settings/get_settings.rs @@ -378,15 +378,15 @@ async fn error_update_settings_unknown_field() { async fn test_partial_update() { let server = Server::new().await; let index = server.index("test"); - let (_response, _code) = index.update_settings(json!({"displayedAttributes": ["foo"]})).await; - index.wait_task(0).await; + let (task, _code) = index.update_settings(json!({"displayedAttributes": ["foo"]})).await; + index.wait_task(task.uid()).await; let (response, code) = index.settings().await; assert_eq!(code, 200); assert_eq!(response["displayedAttributes"], json!(["foo"])); assert_eq!(response["searchableAttributes"], json!(["*"])); - let (_response, _) = index.update_settings(json!({"searchableAttributes": ["bar"]})).await; - index.wait_task(1).await; + let (task, _) = index.update_settings(json!({"searchableAttributes": ["bar"]})).await; + index.wait_task(task.uid()).await; let (response, code) = index.settings().await; assert_eq!(code, 200); @@ -398,10 +398,10 @@ async fn test_partial_update() { async fn error_delete_settings_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_response, code) = index.delete_settings().await; + let (task, code) = index.delete_settings().await; assert_eq!(code, 202); - let response = index.wait_task(0).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "failed"); } @@ -422,12 +422,12 @@ async fn reset_all_settings() { let (response, code) = index.add_documents(documents, None).await; assert_eq!(code, 202); assert_eq!(response["taskUid"], 0); - index.wait_task(0).await; + index.wait_task(response.uid()).await; - index + let (update_task,_status_code) = index .update_settings(json!({"displayedAttributes": ["name", "age"], "searchableAttributes": ["name"], "stopWords": ["the"], "filterableAttributes": ["age"], "synonyms": {"puppy": ["dog", "doggo", "potat"] }})) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await; let (response, code) = index.settings().await; assert_eq!(code, 200); assert_eq!(response["displayedAttributes"], json!(["name", "age"])); @@ -436,8 +436,8 @@ async fn reset_all_settings() { assert_eq!(response["synonyms"], json!({"puppy": ["dog", "doggo", "potat"] })); assert_eq!(response["filterableAttributes"], json!(["age"])); - index.delete_settings().await; - index.wait_task(2).await; + let (delete_task,_status_code) = index.delete_settings().await; + index.wait_task(delete_task.uid()).await; let (response, code) = index.settings().await; assert_eq!(code, 200); @@ -456,14 +456,14 @@ async fn reset_all_settings() { async fn update_setting_unexisting_index() { let server = Server::new().await; let index = server.index("test"); - let (_response, code) = index.update_settings(json!({})).await; + let (task, code) = index.update_settings(json!({})).await; assert_eq!(code, 202); - let response = index.wait_task(0).await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); let (_response, code) = index.get().await; assert_eq!(code, 200); - index.delete_settings().await; - let response = index.wait_task(1).await; + let (task,_status_code) = index.delete_settings().await; + let response = index.wait_task(task.uid()).await; assert_eq!(response["status"], "succeeded"); } @@ -506,16 +506,16 @@ async fn set_and_reset_distinct_attribute_with_dedicated_route() { let server = Server::new().await; let index = server.index("test"); - let (_response, _code) = index.update_distinct_attribute(json!("test")).await; - index.wait_task(0).await; + let (task, _code) = index.update_distinct_attribute(json!("test")).await; + index.wait_task(task.uid()).await; let (response, _) = index.get_distinct_attribute().await; assert_eq!(response, "test"); - index.update_distinct_attribute(json!(null)).await; + let (task,_status_code) = index.update_distinct_attribute(json!(null)).await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; let (response, _) = index.get_distinct_attribute().await; diff --git a/crates/meilisearch/tests/settings/proximity_settings.rs b/crates/meilisearch/tests/settings/proximity_settings.rs index 8b206ded4..1bb5fc95a 100644 --- a/crates/meilisearch/tests/settings/proximity_settings.rs +++ b/crates/meilisearch/tests/settings/proximity_settings.rs @@ -29,8 +29,8 @@ async fn attribute_scale_search() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(DOCUMENTS.clone(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(DOCUMENTS.clone(), None).await; + index.wait_task(task.uid()).await; let (response, code) = index .update_settings(json!({ @@ -39,7 +39,7 @@ async fn attribute_scale_search() { })) .await; assert_eq!("202", code.as_str(), "{:?}", response); - index.wait_task(1).await; + index.wait_task(response.uid()).await; // the expected order is [1, 3, 2] instead of [3, 1, 2] // because the attribute scale doesn't make the difference between 1 and 3. @@ -102,16 +102,16 @@ async fn attribute_scale_phrase_search() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(DOCUMENTS.clone(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(DOCUMENTS.clone(), None).await; + index.wait_task(task.uid()).await; - let (_response, _code) = index + let (task, _code) = index .update_settings(json!({ "proximityPrecision": "byAttribute", "rankingRules": ["words", "typo", "proximity"], })) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; // the expected order is [1, 3] instead of [3, 1] // because the attribute scale doesn't make the difference between 1 and 3. @@ -170,25 +170,25 @@ async fn word_scale_set_and_reset() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(DOCUMENTS.clone(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(DOCUMENTS.clone(), None).await; + index.wait_task(task.uid()).await; // Set and reset the setting ensuring the swap between the 2 settings is applied. - let (_response, _code) = index + let (update_task1, _code) = index .update_settings(json!({ "proximityPrecision": "byAttribute", "rankingRules": ["words", "typo", "proximity"], })) .await; - index.wait_task(1).await; + index.wait_task(update_task1.uid()).await; - let (_response, _code) = index + let (update_task2, _code) = index .update_settings(json!({ "proximityPrecision": "byWord", "rankingRules": ["words", "typo", "proximity"], })) .await; - index.wait_task(2).await; + index.wait_task(update_task2.uid()).await; // [3, 1, 2] index @@ -285,8 +285,8 @@ async fn attribute_scale_default_ranking_rules() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(DOCUMENTS.clone(), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(DOCUMENTS.clone(), None).await; + index.wait_task(task.uid()).await; let (response, code) = index .update_settings(json!({ @@ -294,7 +294,7 @@ async fn attribute_scale_default_ranking_rules() { })) .await; assert_eq!("202", code.as_str(), "{:?}", response); - index.wait_task(1).await; + index.wait_task(response.uid()).await; // the expected order is [3, 1, 2] index diff --git a/crates/meilisearch/tests/settings/tokenizer_customization.rs b/crates/meilisearch/tests/settings/tokenizer_customization.rs index 4602e31f7..e4c4420b1 100644 --- a/crates/meilisearch/tests/settings/tokenizer_customization.rs +++ b/crates/meilisearch/tests/settings/tokenizer_customization.rs @@ -1,3 +1,4 @@ +use actix_web::web::resource; use meili_snap::{json_string, snapshot}; use crate::common::Server; @@ -8,14 +9,14 @@ async fn set_and_reset() { let server = Server::new().await; let index = server.index("test"); - let (_response, _code) = index + let (task, _code) = index .update_settings(json!({ "nonSeparatorTokens": ["#", "&"], "separatorTokens": ["&sep", "
"], "dictionary": ["J.R.R.", "J. R. R."], })) .await; - index.wait_task(0).await; + index.wait_task(task.uid()).await; let (response, _) = index.settings().await; snapshot!(json_string!(response["nonSeparatorTokens"]), @r###" @@ -37,7 +38,7 @@ async fn set_and_reset() { ] "###); - index + let (task,_status_code) = index .update_settings(json!({ "nonSeparatorTokens": null, "separatorTokens": null, @@ -45,7 +46,7 @@ async fn set_and_reset() { })) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await; let (response, _) = index.settings().await; snapshot!(json_string!(response["nonSeparatorTokens"]), @"[]"); @@ -73,17 +74,17 @@ async fn set_and_search() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (add_task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(add_task.uid()).await; - let (_response, _code) = index + let (update_task, _code) = index .update_settings(json!({ "nonSeparatorTokens": ["#", "&"], "separatorTokens": ["
", "&sep"], "dictionary": ["#", "A#", "B#", "C#", "D#", "E#", "F#", "G#"], })) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await; index .search(json!({"q": "&", "attributesToHighlight": ["content"]}), |response, code| { @@ -227,10 +228,10 @@ async fn advanced_synergies() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(documents, None).await; - index.wait_task(0).await; + let (add_task,_status_code) = index.add_documents(documents, None).await; + index.wait_task(add_task.uid()).await; - let (_response, _code) = index + let (update_task, _code) = index .update_settings(json!({ "dictionary": ["J.R.R.", "J. R. R."], "synonyms": { @@ -243,7 +244,7 @@ async fn advanced_synergies() { } })) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await; index .search(json!({"q": "J.R.R.", "attributesToHighlight": ["content"]}), |response, code| { @@ -353,7 +354,7 @@ async fn advanced_synergies() { "dictionary": ["J.R.R.", "J. R. R.", "J.K.", "J. K."], })) .await; - index.wait_task(2).await; + index.wait_task(_response.uid()).await; index .search(json!({"q": "jk", "attributesToHighlight": ["content"]}), |response, code| { diff --git a/crates/meilisearch/tests/snapshot/mod.rs b/crates/meilisearch/tests/snapshot/mod.rs index 0d569fc7c..aa094d8fc 100644 --- a/crates/meilisearch/tests/snapshot/mod.rs +++ b/crates/meilisearch/tests/snapshot/mod.rs @@ -129,10 +129,10 @@ async fn perform_on_demand_snapshot() { index.load_test_set().await; - let (task, _) = server.index("doggo").create(Some("bone")).await; + let (task,_status_code) = server.index("doggo").create(Some("bone")).await; index.wait_task(task.uid()).await.succeeded(); - let (task, _) = server.index("doggo").create(Some("bone")).await; + let (task,_status_code) = server.index("doggo").create(Some("bone")).await; index.wait_task(task.uid()).await.failed(); let (task, code) = server.create_snapshot().await; diff --git a/crates/meilisearch/tests/stats/mod.rs b/crates/meilisearch/tests/stats/mod.rs index a02a48a87..8ce86fceb 100644 --- a/crates/meilisearch/tests/stats/mod.rs +++ b/crates/meilisearch/tests/stats/mod.rs @@ -28,10 +28,10 @@ async fn test_healthyness() { async fn stats() { let server = Server::new().await; let index = server.index("test"); - let (_, code) = index.create(Some("id")).await; + let (task, code) = index.create(Some("id")).await; assert_eq!(code, 202); - index.wait_task(0).await; + index.wait_task(task.uid()).await; let (response, code) = server.stats().await; @@ -57,7 +57,7 @@ async fn stats() { assert_eq!(code, 202, "{}", response); assert_eq!(response["taskUid"], 1); - index.wait_task(1).await; + index.wait_task(response.uid()).await; let timestamp = OffsetDateTime::now_utc(); let (response, code) = server.stats().await; diff --git a/crates/meilisearch/tests/swap_indexes/mod.rs b/crates/meilisearch/tests/swap_indexes/mod.rs index 646f773d8..bf84d5823 100644 --- a/crates/meilisearch/tests/swap_indexes/mod.rs +++ b/crates/meilisearch/tests/swap_indexes/mod.rs @@ -15,7 +15,7 @@ async fn swap_indexes() { let (res, code) = b.add_documents(json!({ "id": 1, "index": "b"}), None).await; snapshot!(code, @"202 Accepted"); snapshot!(res["taskUid"], @"1"); - server.wait_task(1).await; + server.wait_task(res.uid()).await; let (tasks, code) = server.tasks().await; snapshot!(code, @"200 OK"); @@ -67,7 +67,7 @@ async fn swap_indexes() { let (res, code) = server.index_swap(json!([{ "indexes": ["a", "b"] }])).await; snapshot!(code, @"202 Accepted"); snapshot!(res["taskUid"], @"2"); - server.wait_task(2).await; + server.wait_task(res.uid()).await; let (tasks, code) = server.tasks().await; snapshot!(code, @"200 OK"); @@ -159,7 +159,7 @@ async fn swap_indexes() { let (res, code) = d.add_documents(json!({ "id": 1, "index": "d"}), None).await; snapshot!(code, @"202 Accepted"); snapshot!(res["taskUid"], @"4"); - server.wait_task(4).await; + server.wait_task(res.uid()).await; // ensure the index creation worked properly let (tasks, code) = server.tasks_filter("limit=2").await; @@ -215,7 +215,7 @@ async fn swap_indexes() { server.index_swap(json!([{ "indexes": ["a", "b"] }, { "indexes": ["c", "d"] } ])).await; snapshot!(res["taskUid"], @"5"); snapshot!(code, @"202 Accepted"); - server.wait_task(5).await; + server.wait_task(res.uid()).await; // ensure the index creation worked properly let (tasks, code) = server.tasks().await; diff --git a/crates/meilisearch/tests/tasks/mod.rs b/crates/meilisearch/tests/tasks/mod.rs index c9d3f31ed..21345c972 100644 --- a/crates/meilisearch/tests/tasks/mod.rs +++ b/crates/meilisearch/tests/tasks/mod.rs @@ -13,8 +13,8 @@ use crate::json; async fn error_get_unexisting_task_status() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; let (response, code) = index.get_task(1).await; let expected_response = json!({ @@ -32,8 +32,8 @@ async fn error_get_unexisting_task_status() { async fn get_task_status() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index + let (create_task,_status_code) = index.create(None).await; + let (add_task,_status_code) = index .add_documents( json!([{ "id": 1, @@ -42,8 +42,8 @@ async fn get_task_status() { None, ) .await; - index.wait_task(0).await; - let (_response, code) = index.get_task(1).await; + index.wait_task(create_task.uid()).await; + let (_response, code) = index.get_task(add_task.uid()).await; assert_eq!(code, 200); // TODO check response format, as per #48 } @@ -52,8 +52,8 @@ async fn get_task_status() { async fn list_tasks() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -149,8 +149,8 @@ async fn list_tasks_with_star_filters() { async fn list_tasks_status_filtered() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -164,7 +164,7 @@ async fn list_tasks_status_filtered() { // assert_eq!(code, 200, "{}", response); // assert_eq!(response["results"].as_array().unwrap().len(), 1); - index.wait_task(1).await; + index.wait_task(response.uid()).await; let (response, code) = index.filtered_tasks(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); @@ -175,8 +175,8 @@ async fn list_tasks_status_filtered() { async fn list_tasks_type_filtered() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -195,8 +195,8 @@ async fn list_tasks_type_filtered() { async fn list_tasks_invalid_canceled_by_filter() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -210,8 +210,8 @@ async fn list_tasks_invalid_canceled_by_filter() { async fn list_tasks_status_and_type_filtered() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; + let (task,_status_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; @@ -278,8 +278,8 @@ async fn test_summarized_task_view() { async fn test_summarized_document_addition_or_update() { let server = Server::new().await; let index = server.index("test"); - index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), None).await; - index.wait_task(0).await; + let (task,_status_code) = index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), None).await; + index.wait_task(task.uid()).await; let (task, _) = index.get_task(0).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -303,8 +303,8 @@ async fn test_summarized_document_addition_or_update() { } "###); - index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; - index.wait_task(1).await; + let (task,_status_code) = index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; + index.wait_task(task.uid()).await; let (task, _) = index.get_task(1).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -333,8 +333,8 @@ async fn test_summarized_document_addition_or_update() { async fn test_summarized_delete_documents_by_batch() { let server = Server::new().await; let index = server.index("test"); - index.delete_batch(vec![1, 2, 3]).await; - index.wait_task(0).await; + let (task,_status_code) = index.delete_batch(vec![1, 2, 3]).await; + index.wait_task(task.uid()).await; let (task, _) = index.get_task(0).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -365,9 +365,9 @@ async fn test_summarized_delete_documents_by_batch() { "###); index.create(None).await; - index.delete_batch(vec![42]).await; - index.wait_task(2).await; - let (task, _) = index.get_task(2).await; + let (del_task,_status_code) = index.delete_batch(vec![42]).await; + index.wait_task(del_task.uid()).await; + let (task, _) = index.get_task(del_task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -397,9 +397,9 @@ async fn test_summarized_delete_documents_by_filter() { let server = Server::new().await; let index = server.index("test"); - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(0).await; - let (task, _) = index.get_task(0).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -429,9 +429,9 @@ async fn test_summarized_delete_documents_by_filter() { "###); index.create(None).await; - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(2).await; - let (task, _) = index.get_task(2).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -461,9 +461,9 @@ async fn test_summarized_delete_documents_by_filter() { "###); index.update_settings(json!({ "filterableAttributes": ["doggo"] })).await; - index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; - index.wait_task(4).await; - let (task, _) = index.get_task(4).await; + let (task,_status_code) = index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -492,9 +492,9 @@ async fn test_summarized_delete_documents_by_filter() { async fn test_summarized_delete_document_by_id() { let server = Server::new().await; let index = server.index("test"); - index.delete_document(1).await; - index.wait_task(0).await; - let (task, _) = index.get_task(0).await; + let (task,_status_code) = index.delete_document(1).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -524,9 +524,9 @@ async fn test_summarized_delete_document_by_id() { "###); index.create(None).await; - index.delete_document(42).await; - index.wait_task(2).await; - let (task, _) = index.get_task(2).await; + let (task,_status_code) = index.delete_document(42).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -567,9 +567,9 @@ async fn test_summarized_settings_update() { } "###); - index.update_settings(json!({ "displayedAttributes": ["doggos", "name"], "filterableAttributes": ["age", "nb_paw_pads"], "sortableAttributes": ["iq"] })).await; - index.wait_task(0).await; - let (task, _) = index.get_task(0).await; + let (task,_status_code) = index.update_settings(json!({ "displayedAttributes": ["doggos", "name"], "filterableAttributes": ["age", "nb_paw_pads"], "sortableAttributes": ["iq"] })).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -606,9 +606,9 @@ async fn test_summarized_settings_update() { async fn test_summarized_index_creation() { let server = Server::new().await; let index = server.index("test"); - index.create(None).await; - index.wait_task(0).await; - let (task, _) = index.get_task(0).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -630,9 +630,9 @@ async fn test_summarized_index_creation() { } "###); - index.create(Some("doggos")).await; - index.wait_task(1).await; - let (task, _) = index.get_task(1).await; + let (task,_status_code) = index.create(Some("doggos")).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -774,9 +774,9 @@ async fn test_summarized_index_update() { let server = Server::new().await; let index = server.index("test"); // If the index doesn't exist yet, we should get errors with or without the primary key. - index.update(None).await; - index.wait_task(0).await; - let (task, _) = index.get_task(0).await; + let (task,_status_code) = index.update(None).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -803,9 +803,9 @@ async fn test_summarized_index_update() { } "###); - index.update(Some("bones")).await; - index.wait_task(1).await; - let (task, _) = index.get_task(1).await; + let (task,_status_code) = index.update(Some("bones")).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -835,9 +835,9 @@ async fn test_summarized_index_update() { // And run the same two tests once the index do exists. index.create(None).await; - index.update(None).await; - index.wait_task(3).await; - let (task, _) = index.get_task(3).await; + let (task,_status_code) = index.update(None).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -859,9 +859,9 @@ async fn test_summarized_index_update() { } "###); - index.update(Some("bones")).await; - index.wait_task(4).await; - let (task, _) = index.get_task(4).await; + let (task,_status_code) = index.update(Some("bones")).await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -887,13 +887,13 @@ async fn test_summarized_index_update() { #[actix_web::test] async fn test_summarized_index_swap() { let server = Server::new().await; - server + let (task,_status_code) = server .index_swap(json!([ { "indexes": ["doggos", "cattos"] } ])) .await; - server.wait_task(0).await; - let (task, _) = server.get_task(0).await; + server.wait_task(task.uid()).await; + let (task, _) = server.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -928,14 +928,14 @@ async fn test_summarized_index_swap() { "###); server.index("doggos").create(None).await; - server.index("cattos").create(None).await; + let (task,_status_code) = server.index("cattos").create(None).await; server .index_swap(json!([ { "indexes": ["doggos", "cattos"] } ])) .await; - server.wait_task(3).await; - let (task, _) = server.get_task(3).await; + server.wait_task(task.uid()).await; + let (task, _) = server.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -970,11 +970,11 @@ async fn test_summarized_task_cancelation() { let server = Server::new().await; let index = server.index("doggos"); // to avoid being flaky we're only going to cancel an already finished task :( - index.create(None).await; - index.wait_task(0).await; - server.cancel_tasks("uids=0").await; - index.wait_task(1).await; - let (task, _) = index.get_task(1).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = server.cancel_tasks("uids=0").await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -1004,11 +1004,11 @@ async fn test_summarized_task_deletion() { let server = Server::new().await; let index = server.index("doggos"); // to avoid being flaky we're only going to delete an already finished task :( - index.create(None).await; - index.wait_task(0).await; - server.delete_tasks("uids=0").await; - index.wait_task(1).await; - let (task, _) = index.get_task(1).await; + let (task,_status_code) = index.create(None).await; + index.wait_task(task.uid()).await; + let (task,_status_code) = server.delete_tasks("uids=0").await; + index.wait_task(task.uid()).await; + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -1036,9 +1036,9 @@ async fn test_summarized_task_deletion() { #[actix_web::test] async fn test_summarized_dump_creation() { let server = Server::new().await; - server.create_dump().await; - server.wait_task(0).await; - let (task, _) = server.get_task(0).await; + let (task,_status_code) = server.create_dump().await; + server.wait_task(task.uid()).await; + let (task, _) = server.get_task(task.uid()).await; assert_json_snapshot!(task, { ".details.dumpUid" => "[dumpUid]", ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###"