5182: Remove hard coded task ids to prevent flaky tests r=irevoire a=mhmoudr

# Pull Request

## Related issue
Fixes partial #4840

## What does this PR do?
- Mainly scan the test code for any hard coded task Id and replace it by the returned task Id once the action or task is performed on an index.
- PS: _PR is not split by files as it has one theme applied to all tests which make it easy to review_ 


## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Mahmoud Rawas <mhmoudr@gmail.com>
Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
meili-bors[bot] 2025-01-13 15:18:55 +00:00 committed by GitHub
commit e568dbbabb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 733 additions and 727 deletions

View File

@ -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() {

View File

@ -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");

View File

@ -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]" },

View File

@ -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

View File

@ -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");
}

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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.",

View File

@ -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();

View File

@ -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();

View File

@ -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),

View File

@ -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;

View File

@ -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| {

View File

@ -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

View File

@ -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(

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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| {

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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", "<br/>"],
"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": ["<br/>", "&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| {

View File

@ -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",

View File

@ -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(

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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###"

View File

@ -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

View File

@ -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!({