4730: fix a possibly flaky test r=irevoire a=irevoire

On slow CI, it was possible for a document addition to _not_ to be processed and then get autobatched with an index deletion, which changed their task summary details in the end.
Now, I wait for the task to finish, and the result will always be the same

Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
meili-bors[bot] 2024-06-26 07:32:51 +00:00 committed by GitHub
commit 2c09c324f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ mod errors;
mod webhook; mod webhook;
use meili_snap::insta::assert_json_snapshot; use meili_snap::insta::assert_json_snapshot;
use meili_snap::snapshot;
use time::format_description::well_known::Rfc3339; use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime; use time::OffsetDateTime;
@ -738,11 +739,9 @@ async fn test_summarized_index_creation() {
async fn test_summarized_index_deletion() { async fn test_summarized_index_deletion() {
let server = Server::new().await; let server = Server::new().await;
let index = server.index("test"); let index = server.index("test");
index.delete().await; let (ret, _code) = index.delete().await;
index.wait_task(0).await; let task = index.wait_task(ret.uid()).await;
let (task, _) = index.get_task(0).await; snapshot!(task,
assert_json_snapshot!(task,
{ ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" },
@r###" @r###"
{ {
"uid": 0, "uid": 0,
@ -767,12 +766,34 @@ async fn test_summarized_index_deletion() {
"###); "###);
// is the details correctly set when documents are actually deleted. // is the details correctly set when documents are actually deleted.
index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await; // /!\ We need to wait for the document addition to be processed otherwise, if the test runs too slow,
index.delete().await; // both tasks may get autobatched and the deleted documents count will be wrong.
index.wait_task(2).await; let (ret, _code) =
let (task, _) = index.get_task(2).await; index.add_documents(json!({ "id": 42, "content": "doggos & fluff" }), Some("id")).await;
assert_json_snapshot!(task, let task = index.wait_task(ret.uid()).await;
{ ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }, snapshot!(task,
@r###"
{
"uid": 1,
"indexUid": "test",
"status": "succeeded",
"type": "documentAdditionOrUpdate",
"canceledBy": null,
"details": {
"receivedDocuments": 1,
"indexedDocuments": 1
},
"error": null,
"duration": "[duration]",
"enqueuedAt": "[date]",
"startedAt": "[date]",
"finishedAt": "[date]"
}
"###);
let (ret, _code) = index.delete().await;
let task = index.wait_task(ret.uid()).await;
snapshot!(task,
@r###" @r###"
{ {
"uid": 2, "uid": 2,
@ -792,22 +813,25 @@ async fn test_summarized_index_deletion() {
"###); "###);
// What happens when you delete an index that doesn't exists. // What happens when you delete an index that doesn't exists.
index.delete().await; let (ret, _code) = index.delete().await;
index.wait_task(2).await; let task = index.wait_task(ret.uid()).await;
let (task, _) = index.get_task(2).await; snapshot!(task,
assert_json_snapshot!(task,
{ ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" },
@r###" @r###"
{ {
"uid": 2, "uid": 3,
"indexUid": "test", "indexUid": "test",
"status": "succeeded", "status": "failed",
"type": "indexDeletion", "type": "indexDeletion",
"canceledBy": null, "canceledBy": null,
"details": { "details": {
"deletedDocuments": 1 "deletedDocuments": 0
},
"error": {
"message": "Index `test` not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
}, },
"error": null,
"duration": "[duration]", "duration": "[duration]",
"enqueuedAt": "[date]", "enqueuedAt": "[date]",
"startedAt": "[date]", "startedAt": "[date]",