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

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