diff --git a/crates/meilisearch/tests/auth/tenant_token.rs b/crates/meilisearch/tests/auth/tenant_token.rs index 2e3b228d3..a3f89e70b 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.succeeded(); + let (task2,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task2.uid()).await.succeeded(); 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.succeeded(); 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..9059299f3 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.succeeded(); + let (update_task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await.succeeded(); 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.succeeded(); + let (update_task2,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(update_task2.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["color"]})) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await.succeeded(); 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.succeeded(); + let (task,_status_code) = index .update_settings(json!({"filterableAttributes": ["doggos"]})) .await; - index.wait_task(3).await; + index.wait_task(task.uid()).await.succeeded(); 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..70307ac25 100644 --- a/crates/meilisearch/tests/batches/mod.rs +++ b/crates/meilisearch/tests/batches/mod.rs @@ -10,8 +10,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.succeeded(); let (response, code) = index.get_batch(1).await; let expected_response = json!({ @@ -29,8 +29,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.succeeded(); let (_response, code) = index.get_batch(0).await; assert_eq!(code, 200); } @@ -39,8 +39,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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -97,7 +97,7 @@ async fn list_batches_with_star_filters() { let server = Server::new().await; let index = server.index("test"); let (batch, _code) = index.create(None).await; - index.wait_task(batch.uid()).await; + index.wait_task(batch.uid()).await.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -141,25 +141,21 @@ 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 - .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) - .await; + let (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await.succeeded(); + let (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await.failed(); let (response, code) = index.filtered_batches(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 1); - // We can't be sure that the update isn't already processed so we can't test this - // let (response, code) = index.filtered_batches(&[], &["processing"]).await; - // assert_eq!(code, 200, "{}", response); - // assert_eq!(response["results"].as_array().unwrap().len(), 1); - - index.wait_task(1).await; - let (response, code) = index.filtered_batches(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); + assert_eq!(response["results"].as_array().unwrap().len(), 1); + + let (response, code) = index.filtered_batches(&[], &["succeeded", "failed"], &[]).await; + assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 2); } @@ -171,23 +167,26 @@ async fn list_batches_type_filtered() { index.wait_task(task.uid()).await.succeeded(); let (task, _) = index.delete().await; index.wait_task(task.uid()).await.succeeded(); - 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", "IndexDeletion"], &[], &[]).await; assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 2); + + let (response, code) = index.filtered_batches(&["indexCreation"], &[], &[]).await; + assert_eq!(code, 200, "{}", response); + assert_eq!(response["results"].as_array().unwrap().len(), 1); } #[actix_rt::test] 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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -201,8 +200,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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -275,8 +274,9 @@ 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.succeeded(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -306,8 +306,9 @@ 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.succeeded(); let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -342,8 +343,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.failed(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -374,8 +375,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.succeeded(); let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -411,8 +412,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, _status_code) = + index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await.failed(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -444,8 +446,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, _status_code) = + index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await.failed(); let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -477,8 +480,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, _status_code) = + index.delete_document_by_filter(json!({ "filter": "doggo = bernese" })).await; + index.wait_task(task.uid()).await.succeeded(); let (batch, _) = index.get_batch(4).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -514,14 +518,13 @@ 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.failed(); let (batch, _) = index.get_batch(0).await; - assert_json_snapshot!(batch, - { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, + snapshot!(batch, @r#" { - "uid": 0, + "uid": "[uid]", "progress": null, "details": { "providedIds": 1, @@ -546,8 +549,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.succeeded(); let (batch, _) = index.get_batch(2).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -594,8 +597,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.succeeded(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -639,8 +642,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.succeeded(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -667,8 +670,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.failed(); let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -703,7 +706,7 @@ async fn test_summarized_index_deletion() { let server = Server::new().await; let index = server.index("test"); let (ret, _code) = index.delete().await; - let batch = index.wait_task(ret.uid()).await; + let batch = index.wait_task(ret.uid()).await.failed(); snapshot!(batch, @r###" { @@ -734,7 +737,7 @@ async fn test_summarized_index_deletion() { // both batches may get autobatched and the deleted documents count will be wrong. let (ret, _code) = index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; - let batch = index.wait_task(ret.uid()).await; + let batch = index.wait_task(ret.uid()).await.succeeded(); snapshot!(batch, @r###" { @@ -757,7 +760,7 @@ async fn test_summarized_index_deletion() { "###); let (ret, _code) = index.delete().await; - let batch = index.wait_task(ret.uid()).await; + let batch = index.wait_task(ret.uid()).await.succeeded(); snapshot!(batch, @r###" { @@ -780,7 +783,7 @@ async fn test_summarized_index_deletion() { // What happens when you delete an index that doesn't exists. let (ret, _code) = index.delete().await; - let batch = index.wait_task(ret.uid()).await; + let batch = index.wait_task(ret.uid()).await.failed(); snapshot!(batch, @r###" { @@ -812,8 +815,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.failed(); let (batch, _) = index.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -840,8 +843,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.failed(); let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -873,8 +876,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.succeeded(); let (batch, _) = index.get_batch(3).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -901,8 +904,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.succeeded(); let (batch, _) = index.get_batch(4).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -935,12 +938,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.failed(); let (batch, _) = server.get_batch(0).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -975,39 +978,32 @@ 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.succeeded(); + let (batch, _) = server.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r#" { - "uid": 3, + "uid": 1, "progress": null, - "details": { - "swaps": [ - { - "indexes": [ - "doggos", - "cattos" - ] - } - ] - }, + "details": {}, "stats": { "totalNbTasks": 1, "status": { "succeeded": 1 }, "types": { - "indexSwap": 1 + "indexCreation": 1 }, - "indexUids": {} + "indexUids": { + "doggos": 1 + } }, "duration": "[duration]", "startedAt": "[date]", @@ -1021,10 +1017,10 @@ 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 (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await.succeeded(); + let (task, _status_code) = server.cancel_tasks("uids=0").await; + index.wait_task(task.uid()).await.succeeded(); let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -1059,10 +1055,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.succeeded(); + let (task, _status_code) = server.delete_tasks("uids=0").await; + index.wait_task(task.uid()).await.succeeded(); let (batch, _) = index.get_batch(1).await; assert_json_snapshot!(batch, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -1095,8 +1091,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/common/mod.rs b/crates/meilisearch/tests/common/mod.rs index 44385752e..52aa3b32d 100644 --- a/crates/meilisearch/tests/common/mod.rs +++ b/crates/meilisearch/tests/common/mod.rs @@ -46,11 +46,11 @@ impl Value { // Panic if the json doesn't contain the `status` field set to "succeeded" #[track_caller] - pub fn succeeded(&self) -> &Self { + pub fn succeeded(&self) -> Self { if !self.is_success() { panic!("Called succeeded on {}", serde_json::to_string_pretty(&self.0).unwrap()); } - self + self.clone() } /// Return `true` if the `status` field is set to `failed`. @@ -65,11 +65,11 @@ impl Value { // Panic if the json doesn't contain the `status` field set to "succeeded" #[track_caller] - pub fn failed(&self) -> &Self { + pub fn failed(&self) -> Self { if !self.is_fail() { panic!("Called failed on {}", serde_json::to_string_pretty(&self.0).unwrap()); } - self + self.clone() } } @@ -426,7 +426,7 @@ pub async fn shared_index_with_test_set() -> &'static Index<'static, Shared> { ) .await; assert_eq!(code, 202); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index }) .await diff --git a/crates/meilisearch/tests/documents/add_documents.rs b/crates/meilisearch/tests/documents/add_documents.rs index 7eedeed3d..67dc87ad3 100644 --- a/crates/meilisearch/tests/documents/add_documents.rs +++ b/crates/meilisearch/tests/documents/add_documents.rs @@ -980,7 +980,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.succeeded(); let (response, code) = index.get_task(0).await; snapshot!(code, @"200 OK"); @@ -1059,9 +1059,9 @@ async fn document_addition_with_primary_key() { } "###); - index.wait_task(0).await; + index.wait_task(response.uid()).await.succeeded(); - 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 +1169,7 @@ async fn replace_document() { } "###); - index.wait_task(0).await; + index.wait_task(response.uid()).await.succeeded(); let documents = json!([ { @@ -1178,12 +1178,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.succeeded(); - 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###" @@ -1353,9 +1353,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.failed(); + 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###" @@ -1391,7 +1391,7 @@ async fn error_add_documents_bad_document_id() { } ]); let (value, _code) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.failed(); let (response, code) = index.get_task(value.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1428,7 +1428,7 @@ async fn error_add_documents_bad_document_id() { } ]); let (value, _code) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.failed(); let (response, code) = index.get_task(value.uid()).await; snapshot!(code, @"200 OK"); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @@ -1469,9 +1469,9 @@ async fn error_add_documents_missing_document_id() { "content": "foobar" } ]); - 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.failed(); + 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###" @@ -1519,7 +1519,7 @@ async fn error_document_field_limit_reached_in_one_document() { let (response, code) = index.update_documents(documents, Some("id")).await; snapshot!(code, @"202 Accepted"); - let response = index.wait_task(response.uid()).await; + let response = index.wait_task(response.uid()).await.failed(); snapshot!(code, @"202 Accepted"); // Documents without a primary key are not accepted. snapshot!(response, @@ -1781,8 +1781,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###" { @@ -1820,9 +1820,9 @@ async fn add_documents_invalid_geo_field() { } ]); - 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.failed(); + 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###" @@ -1858,9 +1858,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(3).await; - let (response, code) = index.get_task(3).await; + let (task, _status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await.failed(); + 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###" @@ -1896,9 +1896,9 @@ async fn add_documents_invalid_geo_field() { } ]); - index.add_documents(documents, None).await; - index.wait_task(4).await; - let (response, code) = index.get_task(4).await; + let (task, _status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await.failed(); + 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###" @@ -1934,9 +1934,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.failed(); + 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###" @@ -1972,9 +1972,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.failed(); + 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###" @@ -2010,9 +2010,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.failed(); + 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###" @@ -2048,9 +2048,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.failed(); + 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###" @@ -2086,9 +2086,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.failed(); + 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###" @@ -2124,9 +2124,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.failed(); + 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###" @@ -2162,9 +2162,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.failed(); + 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###" @@ -2200,9 +2200,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.failed(); + 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###" @@ -2238,9 +2238,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.failed(); + 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###" @@ -2280,7 +2280,7 @@ async fn add_documents_invalid_geo_field() { let (response, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - let response = index.wait_task(response.uid()).await; + let response = index.wait_task(response.uid()).await.failed(); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" { @@ -2317,7 +2317,7 @@ async fn add_documents_invalid_geo_field() { let (response, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - let response = index.wait_task(response.uid()).await; + let response = index.wait_task(response.uid()).await.failed(); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" { @@ -2354,7 +2354,7 @@ async fn add_documents_invalid_geo_field() { let (response, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - let response = index.wait_task(response.uid()).await; + let response = index.wait_task(response.uid()).await.failed(); snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), @r###" { @@ -2398,7 +2398,7 @@ async fn add_invalid_geo_and_then_settings() { ]); let (ret, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - let ret = index.wait_task(ret.uid()).await; + let ret = index.wait_task(ret.uid()).await.succeeded(); snapshot!(ret, @r###" { "uid": "[uid]", @@ -2421,7 +2421,7 @@ async fn add_invalid_geo_and_then_settings() { let (ret, code) = index.update_settings(json!({ "sortableAttributes": ["_geo"] })).await; snapshot!(code, @"202 Accepted"); - let ret = index.wait_task(ret.uid()).await; + let ret = index.wait_task(ret.uid()).await.failed(); snapshot!(ret, @r###" { "uid": "[uid]", @@ -2488,9 +2488,9 @@ async fn error_primary_key_inference() { } ]); - index.add_documents(documents, None).await; - index.wait_task(0).await; - let (response, code) = index.get_task(0).await; + let (task, _status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await.failed(); + 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]" }), @@ -2529,9 +2529,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.failed(); + 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]" }), @@ -2568,9 +2568,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.succeeded(); + 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]" }), @@ -2607,14 +2607,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.succeeded(); + 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.succeeded(); + 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..918343f94 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,12 @@ 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.succeeded(); + let (task, status_code) = server.index("test").delete_document(0).await; + assert_eq!(status_code, 202); + index.wait_task(task.uid()).await.succeeded(); let (_response, code) = index.get_document(0, None).await; assert_eq!(code, 404); @@ -44,10 +45,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 +57,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.succeeded(); + 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,12 +77,12 @@ 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.succeeded(); + 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; 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.succeeded(); + 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.succeeded(); 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.succeeded(); 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.succeeded(); 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/create_index.rs b/crates/meilisearch/tests/index/create_index.rs index 9b9fbd039..e8efd14e2 100644 --- a/crates/meilisearch/tests/index/create_index.rs +++ b/crates/meilisearch/tests/index/create_index.rs @@ -115,7 +115,7 @@ async fn create_index_with_primary_key() { assert_eq!(response["status"], "enqueued"); - let response = index.wait_task(response.uid()).await; + let response = index.wait_task(response.uid()).await.succeeded(); assert_eq!(response["status"], "succeeded"); assert_eq!(response["type"], "indexCreation"); @@ -130,8 +130,7 @@ async fn create_index_with_invalid_primary_key() { let index = server.unique_index(); let (response, code) = index.add_documents(documents, Some("title")).await; assert_eq!(code, 202); - - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.failed(); let (response, code) = index.get().await; assert_eq!(code, 200); @@ -141,8 +140,7 @@ async fn create_index_with_invalid_primary_key() { let (response, code) = index.add_documents(documents, Some("id")).await; assert_eq!(code, 202); - - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.failed(); let (response, code) = index.get().await; assert_eq!(code, 200); diff --git a/crates/meilisearch/tests/index/get_index.rs b/crates/meilisearch/tests/index/get_index.rs index 5e3098751..1cdf2da44 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.succeeded(); 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.succeeded(); 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..291cb0ce0 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.succeeded(); 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.succeeded(); 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..a9b02e7d4 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.succeeded(); - 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/logs/mod.rs b/crates/meilisearch/tests/logs/mod.rs index 26482b561..e4dc50a9c 100644 --- a/crates/meilisearch/tests/logs/mod.rs +++ b/crates/meilisearch/tests/logs/mod.rs @@ -94,7 +94,7 @@ async fn basic_test_log_stream_route() { "enqueuedAt": "[date]" } "###); - server.wait_task(ret.uid()).await; + server.wait_task(ret.uid()).await.succeeded(); let req = actix_web::test::TestRequest::delete().uri("/logs/stream"); let req = req.to_request(); diff --git a/crates/meilisearch/tests/search/distinct.rs b/crates/meilisearch/tests/search/distinct.rs index 2023c01a8..094ef7bbf 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.succeeded(); 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.succeeded(); fn get_hits(response: &Value) -> Vec<&str> { let hits_array = response["hits"].as_array().unwrap(); diff --git a/crates/meilisearch/tests/search/errors.rs b/crates/meilisearch/tests/search/errors.rs index ab50e2aa1..9dea42b12 100644 --- a/crates/meilisearch/tests/search/errors.rs +++ b/crates/meilisearch/tests/search/errors.rs @@ -640,7 +640,7 @@ async fn filter_invalid_syntax_object() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); index .search(json!({"filter": "title & Glass"}), |response, code| { @@ -663,7 +663,7 @@ async fn filter_invalid_syntax_array() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); index .search(json!({"filter": ["title & Glass"]}), |response, code| { @@ -686,7 +686,7 @@ async fn filter_invalid_syntax_string() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "Found unexpected characters at the end of the filter: `XOR title = Glass`. You probably forgot an `OR` or an `AND` rule.\n15:32 title = Glass XOR title = Glass", @@ -708,7 +708,7 @@ async fn filter_invalid_attribute_array() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": format!("Index `{}`: Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", index.uid), @@ -730,7 +730,7 @@ async fn filter_invalid_attribute_string() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": format!("Index `{}`: Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", index.uid), @@ -752,7 +752,7 @@ async fn filter_reserved_geo_attribute_array() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -774,7 +774,7 @@ async fn filter_reserved_geo_attribute_string() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -796,7 +796,7 @@ async fn filter_reserved_attribute_array() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -818,7 +818,7 @@ async fn filter_reserved_attribute_string() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -840,7 +840,7 @@ async fn filter_reserved_geo_point_array() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", @@ -862,7 +862,7 @@ async fn filter_reserved_geo_point_string() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", @@ -884,7 +884,7 @@ async fn sort_geo_reserved_attribute() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a sort expression. Use the _geoPoint(latitude, longitude) built-in rule to sort on _geo field coordinates.", @@ -911,7 +911,7 @@ async fn sort_reserved_attribute() { let index = server.unique_index(); let (task, _code) = index.update_settings(json!({"sortableAttributes": ["id"]})).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a sort expression.", @@ -1095,7 +1095,7 @@ async fn distinct_at_search_time() { assert_eq!(code, 400); let (task, _) = index.update_settings_filterable_attributes(json!(["color", "machin"])).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": format!("Index `{}`: Attribute `doggo.truc` is not filterable and thus, cannot be used as distinct attribute. Available filterable attributes are: `color, machin`.", index.uid), @@ -1109,7 +1109,7 @@ async fn distinct_at_search_time() { assert_eq!(code, 400); let (task, _) = index.update_settings_displayed_attributes(json!(["color"])).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); let expected_response = json!({ "message": format!("Index `{}`: Attribute `doggo.truc` is not filterable and thus, cannot be used as distinct attribute. Available filterable attributes are: `color, <..hidden-attributes>`.", index.uid), diff --git a/crates/meilisearch/tests/search/facet_search.rs b/crates/meilisearch/tests/search/facet_search.rs index 696c23f91..7e46c5d15 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); let (response, code) = index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await; diff --git a/crates/meilisearch/tests/search/formatted.rs b/crates/meilisearch/tests/search/formatted.rs index 5ded39976..38935da5f 100644 --- a/crates/meilisearch/tests/search/formatted.rs +++ b/crates/meilisearch/tests/search/formatted.rs @@ -65,7 +65,7 @@ async fn formatted_contain_wildcard() { let documents = NESTED_DOCUMENTS.clone(); let (response, _) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index.search(json!({ "q": "pésti", "attributesToRetrieve": ["father", "mother"], "attributesToHighlight": ["father", "mother", "*"], "attributesToCrop": ["doggos"], "showMatchesPosition": true }), |response, code| @@ -398,7 +398,7 @@ async fn displayedattr_2_smol() { let documents = NESTED_DOCUMENTS.clone(); let (response, _) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index .search(json!({ "attributesToRetrieve": ["father", "id"], "attributesToHighlight": ["mother"], "attributesToCrop": ["cattos"] }), @@ -596,7 +596,7 @@ async fn test_cjk_highlight() { { "id": 1, "title": "大卫到了扫罗那里" }, ]); let (response, _) = index.add_documents(documents, None).await; - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index .search(json!({"q": "で", "attributesToHighlight": ["title"]}), |response, code| { diff --git a/crates/meilisearch/tests/search/geo.rs b/crates/meilisearch/tests/search/geo.rs index e92056191..b0cc8b6ca 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.succeeded(); index .search( @@ -128,7 +128,7 @@ async fn bug_4640() { index.add_documents(documents, None).await; index.update_settings_filterable_attributes(json!(["_geo"])).await; let (ret, _code) = index.update_settings_sortable_attributes(json!(["_geo"])).await; - index.wait_task(ret.uid()).await; + index.wait_task(ret.uid()).await.succeeded(); // Sort the document with the second one first index diff --git a/crates/meilisearch/tests/search/hybrid.rs b/crates/meilisearch/tests/search/hybrid.rs index c8334858a..5c1a3bbff 100644 --- a/crates/meilisearch/tests/search/hybrid.rs +++ b/crates/meilisearch/tests/search/hybrid.rs @@ -30,11 +30,11 @@ async fn index_with_documents_user_provided<'a>( "dimensions": 2}}} )) .await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.add_documents(documents.clone(), None).await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index } @@ -63,11 +63,11 @@ async fn index_with_documents_hf<'a>(server: &'a Server, documents: &Value) -> I }}} )) .await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.add_documents(documents.clone(), None).await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); index } @@ -573,7 +573,7 @@ async fn retrieve_vectors() { .update_settings(json!({ "displayedAttributes": ["id", "title", "desc", "_vectors"]} )) .await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index .search_post( @@ -623,7 +623,7 @@ async fn retrieve_vectors() { let (response, code) = index.update_settings(json!({ "displayedAttributes": ["id", "title", "desc"]} )).await; assert_eq!(202, code, "{:?}", response); - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index .search_post( diff --git a/crates/meilisearch/tests/search/locales.rs b/crates/meilisearch/tests/search/locales.rs index c01d854e2..282589d6a 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.succeeded(); // 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.succeeded(); // 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.succeeded(); // 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.succeeded(); // 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.succeeded(); // 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.succeeded(); // 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.succeeded(); 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.succeeded(); // 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.succeeded(); 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.succeeded(); // chinese index @@ -861,7 +861,7 @@ async fn settings_change() { "enqueuedAt": "[date]" } "###); - index.wait_task(2).await; + index.wait_task(response.uid()).await.succeeded(); // 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); // infer swedish index @@ -1286,7 +1286,7 @@ async fn german_search() { ] })) .await; - index.wait_task(1).await; + index.wait_task(_response.uid()).await.succeeded(); // infer swedish index diff --git a/crates/meilisearch/tests/search/matching_strategy.rs b/crates/meilisearch/tests/search/matching_strategy.rs index a4cb19f62..3b4325c10 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.succeeded(); index } diff --git a/crates/meilisearch/tests/search/mod.rs b/crates/meilisearch/tests/search/mod.rs index 057b2b3a2..0046964fa 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.succeeded(); index .search(json!({"q": "how \"to\" train \"the" }), |response, code| { @@ -218,11 +218,12 @@ 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.succeeded(); - 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.succeeded(); // There is a synonym for escape -> glass but we don't want "escape", only the derivates: glass index @@ -247,8 +248,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.succeeded(); index .search(json!({"q": "東京"}), |response, code| { @@ -270,11 +271,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.succeeded(); - 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.succeeded(); index .search(json!({"q": "สบู"}), |response, code| { @@ -329,9 +330,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 +354,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 +608,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.succeeded(); let (response, code) = index.search_post(json!({ "attributesToRetrieve": ["title", "id"] })).await; @@ -622,8 +623,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.succeeded(); index .search( @@ -650,8 +651,9 @@ 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.succeeded(); index .search( @@ -685,8 +687,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.succeeded(); index .search( @@ -715,8 +717,9 @@ 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.succeeded(); index .search( @@ -754,8 +757,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.succeeded(); index .search( @@ -770,8 +773,9 @@ 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.succeeded(); index .search( @@ -795,7 +799,7 @@ async fn test_score_details() { let documents = DOCUMENTS.clone(); let res = index.add_documents(json!(documents), None).await; - index.wait_task(res.0.uid()).await; + index.wait_task(res.0.uid()).await.succeeded(); index .search( @@ -868,7 +872,7 @@ async fn test_score() { let documents = SCORE_DOCUMENTS.clone(); let res = index.add_documents(json!(documents), None).await; - index.wait_task(res.0.uid()).await; + index.wait_task(res.0.uid()).await.succeeded(); index .search( @@ -921,7 +925,7 @@ async fn test_score_threshold() { let documents = SCORE_DOCUMENTS.clone(); let res = index.add_documents(json!(documents), None).await; - index.wait_task(res.0.uid()).await; + index.wait_task(res.0.uid()).await.succeeded(); index .search( @@ -1077,7 +1081,7 @@ async fn test_degraded_score_details() { index.add_documents(json!(documents), None).await; // We can't really use anything else than 0ms here; otherwise, the test will get flaky. let (res, _code) = index.update_settings(json!({ "searchCutoffMs": 0 })).await; - index.wait_task(res.uid()).await; + index.wait_task(res.uid()).await.succeeded(); index .search( @@ -1162,8 +1166,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.succeeded(); let (response, code) = index .search_post(json!({ @@ -1369,8 +1373,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.succeeded(); index .search(json!({"q": "deLonghi"}), |response, code| { @@ -1587,13 +1591,14 @@ 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.succeeded(); index .search(json!({"q": "How to train"}), |response, code| { @@ -1679,11 +1684,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.succeeded(); - 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.succeeded(); // search index diff --git a/crates/meilisearch/tests/search/multi.rs b/crates/meilisearch/tests/search/multi.rs index 9377f435a..5b0144d45 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); let (response, code) = server .multi_search(json!({"queries": [ @@ -1280,14 +1280,14 @@ async fn federation_filter() { let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings( json!({"searchableAttributes": ["name"], "filterableAttributes": ["BOOST"]}), ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -1348,7 +1348,7 @@ async fn federation_sort_same_indexes_same_criterion_same_direction() { let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -1363,7 +1363,7 @@ async fn federation_sort_same_indexes_same_criterion_same_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // two identical placeholder search should have all results from first query let (response, code) = server @@ -1611,7 +1611,7 @@ async fn federation_sort_same_indexes_same_criterion_opposite_direction() { let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -1626,7 +1626,7 @@ async fn federation_sort_same_indexes_same_criterion_opposite_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // two identical placeholder search should have all results from first query let (response, code) = server @@ -1671,7 +1671,7 @@ async fn federation_sort_same_indexes_different_criterion_same_direction() { let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -1686,7 +1686,7 @@ async fn federation_sort_same_indexes_different_criterion_same_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // return mothers and fathers ordered accross fields. let (response, code) = server @@ -1935,7 +1935,7 @@ async fn federation_sort_same_indexes_different_criterion_opposite_direction() { let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -1950,7 +1950,7 @@ async fn federation_sort_same_indexes_different_criterion_opposite_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // two identical placeholder search should have all results from first query let (response, code) = server @@ -1995,7 +1995,7 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2010,13 +2010,13 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2031,7 +2031,7 @@ async fn federation_sort_different_indexes_same_criterion_same_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // return titles ordered accross indexes let (response, code) = server @@ -2307,7 +2307,7 @@ async fn federation_sort_different_ranking_rules() { let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2322,13 +2322,13 @@ async fn federation_sort_different_ranking_rules() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2343,7 +2343,7 @@ async fn federation_sort_different_ranking_rules() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // return titles ordered accross indexes let (response, code) = server @@ -2546,7 +2546,7 @@ async fn federation_sort_different_indexes_same_criterion_opposite_direction() { let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2561,13 +2561,13 @@ async fn federation_sort_different_indexes_same_criterion_opposite_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2582,7 +2582,7 @@ async fn federation_sort_different_indexes_same_criterion_opposite_direction() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // all results from query 0 let (response, code) = server @@ -2628,7 +2628,7 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2643,13 +2643,13 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2664,7 +2664,7 @@ async fn federation_sort_different_indexes_different_criterion_same_direction() ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // return titles ordered accross indexes let (response, code) = server @@ -2940,7 +2940,7 @@ async fn federation_sort_different_indexes_different_criterion_opposite_directio let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2955,13 +2955,13 @@ async fn federation_sort_different_indexes_different_criterion_opposite_directio ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -2976,7 +2976,7 @@ async fn federation_sort_different_indexes_different_criterion_opposite_directio ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // all results from query 0 first let (response, code) = server @@ -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.succeeded(); 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.succeeded(); 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.succeeded(); { 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.succeeded(); 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.succeeded(); 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.succeeded(); { let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -3685,14 +3685,14 @@ async fn federation_invalid_weight() { let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings( json!({"searchableAttributes": ["name"], "filterableAttributes": ["BOOST"]}), ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -3719,14 +3719,14 @@ async fn federation_null_weight() { let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings( json!({"searchableAttributes": ["name"], "filterableAttributes": ["BOOST"]}), ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -3787,7 +3787,7 @@ async fn federation_federated_contains_pagination() { let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // fail when a federated query contains "limit" let (response, code) = server @@ -3867,11 +3867,11 @@ async fn federation_federated_contains_facets() { ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // empty facets are actually OK let (response, code) = server @@ -3951,7 +3951,7 @@ async fn federation_non_faceted_for_an_index() { ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("fruits-no-name"); @@ -3961,17 +3961,17 @@ async fn federation_non_faceted_for_an_index() { ) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("fruits-no-facets"); let (value, _) = index.update_settings(json!({"searchableAttributes": ["name"]})).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // fails let (response, code) = server @@ -4071,7 +4071,7 @@ async fn federation_non_federated_contains_federation_option() { let documents = FRUITS_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // fail when a non-federated query contains "federationOptions" let (response, code) = server @@ -4116,12 +4116,12 @@ async fn federation_vector_single_index() { } }})) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let documents = VECTOR_DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // same embedder let (response, code) = server @@ -4320,12 +4320,12 @@ async fn federation_vector_two_indexes() { }, }})) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let documents = VECTOR_DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("vectors-sentiment"); @@ -4337,12 +4337,12 @@ async fn federation_vector_two_indexes() { } }})) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let documents = VECTOR_DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = server .multi_search(json!({"federation": {}, "queries": [ @@ -4802,7 +4802,7 @@ async fn federation_facets_different_indexes_same_facet() { let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -4818,13 +4818,13 @@ async fn federation_facets_different_indexes_same_facet() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -4840,13 +4840,13 @@ async fn federation_facets_different_indexes_same_facet() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman-2"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -4862,7 +4862,7 @@ async fn federation_facets_different_indexes_same_facet() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // return titles ordered accross indexes let (response, code) = server @@ -5369,7 +5369,7 @@ async fn federation_facets_same_indexes() { let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -5384,13 +5384,13 @@ async fn federation_facets_same_indexes() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("doggos-2"); let documents = NESTED_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -5405,7 +5405,7 @@ async fn federation_facets_same_indexes() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = server .multi_search(json!({"federation": { @@ -5670,7 +5670,7 @@ async fn federation_inconsistent_merge_order() { let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -5686,13 +5686,13 @@ async fn federation_inconsistent_merge_order() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("movies-2"); let documents = DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -5711,13 +5711,13 @@ async fn federation_inconsistent_merge_order() { } })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let index = server.index("batman"); let documents = SCORE_DOCUMENTS.clone(); let (value, _) = index.add_documents(documents, None).await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (value, _) = index .update_settings(json!({ @@ -5733,7 +5733,7 @@ async fn federation_inconsistent_merge_order() { ] })) .await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // without merging, it works let (response, code) = server diff --git a/crates/meilisearch/tests/search/restrict_searchable.rs b/crates/meilisearch/tests/search/restrict_searchable.rs index abd13fadf..ce99c4047 100644 --- a/crates/meilisearch/tests/search/restrict_searchable.rs +++ b/crates/meilisearch/tests/search/restrict_searchable.rs @@ -64,8 +64,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.succeeded(); index .search( @@ -77,8 +77,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.succeeded(); index .search( @@ -108,8 +108,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.succeeded(); index .search(json!({"q": "Captain Marvel", "attributesToSearchOn": ["*"]}), |response, code| { @@ -191,8 +191,10 @@ 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.succeeded(); // simple search should return 2 documents (ids: 2 and 3). index @@ -358,7 +360,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.succeeded(); // 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..2c5b7517f 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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 eb7efabea..b09867572 100644 --- a/crates/meilisearch/tests/settings/get_settings.rs +++ b/crates/meilisearch/tests/settings/get_settings.rs @@ -193,7 +193,7 @@ async fn get_settings() { let server = Server::new().await; let index = server.index("test"); let (response, _code) = index.create(None).await; - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index.settings().await; assert_eq!(code, 200); let settings = response.as_object().unwrap(); @@ -250,7 +250,7 @@ async fn secrets_are_hidden_in_settings() { let index = server.index("test"); let (response, _code) = index.create(None).await; - index.wait_task(response.uid()).await; + index.wait_task(response.uid()).await.succeeded(); let (response, code) = index .update_settings(json!({ @@ -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.succeeded(); 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.succeeded(); 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.succeeded(); - 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.succeeded(); 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.succeeded(); 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.succeeded(); 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.succeeded(); 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..c5897bc51 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.succeeded(); 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.succeeded(); // 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.succeeded(); - 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.succeeded(); // 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.succeeded(); // 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.succeeded(); - 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.succeeded(); // [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.succeeded(); 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.succeeded(); // 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..190918b34 100644 --- a/crates/meilisearch/tests/settings/tokenizer_customization.rs +++ b/crates/meilisearch/tests/settings/tokenizer_customization.rs @@ -8,14 +8,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.succeeded(); let (response, _) = index.settings().await; snapshot!(json_string!(response["nonSeparatorTokens"]), @r###" @@ -37,7 +37,7 @@ async fn set_and_reset() { ] "###); - index + let (task, _status_code) = index .update_settings(json!({ "nonSeparatorTokens": null, "separatorTokens": null, @@ -45,7 +45,7 @@ async fn set_and_reset() { })) .await; - index.wait_task(1).await; + index.wait_task(task.uid()).await.succeeded(); let (response, _) = index.settings().await; snapshot!(json_string!(response["nonSeparatorTokens"]), @"[]"); @@ -73,17 +73,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.succeeded(); - 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.succeeded(); index .search(json!({"q": "&", "attributesToHighlight": ["content"]}), |response, code| { @@ -227,10 +227,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.succeeded(); - let (_response, _code) = index + let (update_task, _code) = index .update_settings(json!({ "dictionary": ["J.R.R.", "J. R. R."], "synonyms": { @@ -243,7 +243,7 @@ async fn advanced_synergies() { } })) .await; - index.wait_task(1).await; + index.wait_task(update_task.uid()).await.succeeded(); index .search(json!({"q": "J.R.R.", "attributesToHighlight": ["content"]}), |response, code| { @@ -353,7 +353,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.succeeded(); index .search(json!({"q": "jk", "attributesToHighlight": ["content"]}), |response, code| { diff --git a/crates/meilisearch/tests/similar/errors.rs b/crates/meilisearch/tests/similar/errors.rs index 86fca97ad..c19c0b654 100644 --- a/crates/meilisearch/tests/similar/errors.rs +++ b/crates/meilisearch/tests/similar/errors.rs @@ -324,7 +324,7 @@ async fn similar_bad_filter() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (response, code) = index.similar_post(json!({ "id": 287947, "filter": true, "embedder": "manual" })).await; @@ -362,7 +362,7 @@ async fn filter_invalid_syntax_object() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar(json!({"id": 287947, "filter": "title & Glass", "embedder": "manual"}), |response, code| { @@ -401,7 +401,7 @@ async fn filter_invalid_syntax_array() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar(json!({"id": 287947, "filter": ["title & Glass"], "embedder": "manual"}), |response, code| { @@ -440,7 +440,7 @@ async fn filter_invalid_syntax_string() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "Found unexpected characters at the end of the filter: `XOR title = Glass`. You probably forgot an `OR` or an `AND` rule.\n15:32 title = Glass XOR title = Glass", @@ -481,7 +481,7 @@ async fn filter_invalid_attribute_array() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", @@ -522,7 +522,7 @@ async fn filter_invalid_attribute_string() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", @@ -563,7 +563,7 @@ async fn filter_reserved_geo_attribute_array() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -604,7 +604,7 @@ async fn filter_reserved_geo_attribute_string() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:13 _geo = Glass", @@ -645,7 +645,7 @@ async fn filter_reserved_attribute_array() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -686,7 +686,7 @@ async fn filter_reserved_attribute_string() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:21 _geoDistance = Glass", @@ -727,7 +727,7 @@ async fn filter_reserved_geo_point_array() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", @@ -768,7 +768,7 @@ async fn filter_reserved_geo_point_string() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let expected_response = json!({ "message": "`_geoPoint` is a reserved keyword and thus can't be used as a filter expression. Use the `_geoRadius(latitude, longitude, distance)` or `_geoBoundingBox([latitude, longitude], [latitude, longitude])` built-in rules to filter on `_geo` coordinates.\n1:18 _geoPoint = Glass", diff --git a/crates/meilisearch/tests/similar/mod.rs b/crates/meilisearch/tests/similar/mod.rs index fa0797a41..71518f04c 100644 --- a/crates/meilisearch/tests/similar/mod.rs +++ b/crates/meilisearch/tests/similar/mod.rs @@ -77,7 +77,7 @@ async fn basic() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar( @@ -274,7 +274,7 @@ async fn ranking_score_threshold() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar( @@ -555,7 +555,7 @@ async fn filter() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar( @@ -684,7 +684,7 @@ async fn limit_and_offset() { let documents = DOCUMENTS.clone(); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index .similar( diff --git a/crates/meilisearch/tests/snapshot/mod.rs b/crates/meilisearch/tests/snapshot/mod.rs index 0d569fc7c..0f3417cdf 100644 --- a/crates/meilisearch/tests/snapshot/mod.rs +++ b/crates/meilisearch/tests/snapshot/mod.rs @@ -56,7 +56,7 @@ async fn perform_snapshot() { let (task, code) = server.index("test1").create(Some("prim")).await; meili_snap::snapshot!(code, @"202 Accepted"); - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); // wait for the _next task_ to process, aka the snapshot that should be enqueued at some point @@ -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..1b4e458d3 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.succeeded(); 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.succeeded(); 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..f432ef7db 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.succeeded(); 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.succeeded(); + 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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -105,7 +105,7 @@ async fn list_tasks_with_star_filters() { let server = Server::new().await; let index = server.index("test"); let (task, _code) = index.create(None).await; - index.wait_task(task.uid()).await; + index.wait_task(task.uid()).await.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -149,25 +149,21 @@ 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; - index - .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) - .await; + let (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await.succeeded(); + let (task, _status_code) = index.create(None).await; + index.wait_task(task.uid()).await.failed(); let (response, code) = index.filtered_tasks(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 1); - // We can't be sure that the update isn't already processed so we can't test this - // let (response, code) = index.filtered_tasks(&[], &["processing"]).await; - // assert_eq!(code, 200, "{}", response); - // assert_eq!(response["results"].as_array().unwrap().len(), 1); - - index.wait_task(1).await; - let (response, code) = index.filtered_tasks(&[], &["succeeded"], &[]).await; assert_eq!(code, 200, "{}", response); + assert_eq!(response["results"].as_array().unwrap().len(), 1); + + let (response, code) = index.filtered_tasks(&[], &["succeeded", "failed"], &[]).await; + assert_eq!(code, 200, "{}", response); assert_eq!(response["results"].as_array().unwrap().len(), 2); } @@ -175,8 +171,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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -195,8 +191,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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -210,8 +206,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.succeeded(); index .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None) .await; @@ -278,8 +274,9 @@ 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.succeeded(); let (task, _) = index.get_task(0).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -303,8 +300,9 @@ 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.succeeded(); let (task, _) = index.get_task(1).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -333,8 +331,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.failed(); let (task, _) = index.get_task(0).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @@ -365,9 +363,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.succeeded(); + let (task, _) = index.get_task(del_task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -397,9 +395,10 @@ 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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -429,9 +428,10 @@ 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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -461,9 +461,10 @@ 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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -492,9 +493,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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -524,9 +525,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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -567,9 +568,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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -606,9 +607,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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -630,9 +631,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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -774,9 +775,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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -803,9 +804,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.failed(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -835,9 +836,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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -859,9 +860,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.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -887,13 +888,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.failed(); + let (task, _) = server.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -927,15 +928,17 @@ async fn test_summarized_index_swap() { } "###); - server.index("doggos").create(None).await; - server.index("cattos").create(None).await; - server + let (task, _code) = server.index("doggos").create(None).await; + server.wait_task(task.uid()).await.succeeded(); + let (task, _code) = server.index("cattos").create(None).await; + server.wait_task(task.uid()).await.succeeded(); + let (task, _code) = 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.succeeded(); + let (task, _) = server.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -970,11 +973,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.succeeded(); + let (task, _status_code) = server.cancel_tasks("uids=0").await; + index.wait_task(task.uid()).await.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -1004,11 +1007,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.succeeded(); + let (task, _status_code) = server.delete_tasks("uids=0").await; + index.wait_task(task.uid()).await.succeeded(); + let (task, _) = index.get_task(task.uid()).await; assert_json_snapshot!(task, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, @r###" @@ -1036,9 +1039,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###" diff --git a/crates/meilisearch/tests/vector/mod.rs b/crates/meilisearch/tests/vector/mod.rs index adad9fa81..86c865384 100644 --- a/crates/meilisearch/tests/vector/mod.rs +++ b/crates/meilisearch/tests/vector/mod.rs @@ -55,7 +55,7 @@ async fn add_remove_user_provided() { })) .await; snapshot!(code, @"202 Accepted"); - server.wait_task(response.uid()).await; + server.wait_task(response.uid()).await.succeeded(); let documents = json!([ {"id": 0, "name": "kefir", "_vectors": { "manual": [0, 0, 0] }}, @@ -63,7 +63,7 @@ async fn add_remove_user_provided() { ]); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (documents, _code) = index .get_all_documents(GetAllDocumentsOptions { retrieve_vectors: true, ..Default::default() }) @@ -116,7 +116,7 @@ async fn add_remove_user_provided() { ]); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (documents, _code) = index .get_all_documents(GetAllDocumentsOptions { retrieve_vectors: true, ..Default::default() }) @@ -159,7 +159,7 @@ async fn add_remove_user_provided() { let (value, code) = index.delete_document(0).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); let (documents, _code) = index .get_all_documents(GetAllDocumentsOptions { retrieve_vectors: true, ..Default::default() }) @@ -221,7 +221,7 @@ async fn generate_default_user_provided_documents(server: &Server) -> Index { ]); let (value, code) = index.add_documents(documents, None).await; snapshot!(code, @"202 Accepted"); - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); index } @@ -618,7 +618,7 @@ async fn clear_documents() { let index = generate_default_user_provided_documents(&server).await; let (value, _code) = index.clear_all_documents().await; - index.wait_task(value.uid()).await; + index.wait_task(value.uid()).await.succeeded(); // Make sure the documents DB has been cleared let (documents, _code) = index diff --git a/crates/meilisearch/tests/vector/settings.rs b/crates/meilisearch/tests/vector/settings.rs index 027c55219..85b7d2b7f 100644 --- a/crates/meilisearch/tests/vector/settings.rs +++ b/crates/meilisearch/tests/vector/settings.rs @@ -73,7 +73,7 @@ async fn update_embedder() { })) .await; snapshot!(code, @"202 Accepted"); - server.wait_task(response.uid()).await; + server.wait_task(response.uid()).await.succeeded(); let (response, code) = index .update_settings(json!({