4963: test: improve performance of delete_index.rs r=curquiza a=DerTimonius

# Pull Request

## Related issue
related to #4840

## What does this PR do?
This PR follows the instructions in #4840 and improves the performance of `meilisearch/tests/index/delete_index.rs`. The tests run locally, if they fail in the CI I'll try to fix them

## 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: Timon Jurschitsch <timon.jurschitsch@gmail.com>
This commit is contained in:
meili-bors[bot] 2024-10-03 15:40:07 +00:00 committed by GitHub
commit 386ca86297
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 14 deletions

View File

@ -272,6 +272,20 @@ impl<'a> Index<'a, Shared> {
} }
(task, code) (task, code)
} }
pub async fn delete_index_fail(&self) -> (Value, StatusCode) {
let (mut task, code) = self._delete().await;
if code.is_success() {
task = self.wait_task(task.uid()).await;
if task.is_success() {
panic!(
"`delete_index_fail` succeeded: {}",
serde_json::to_string_pretty(&task).unwrap()
);
}
}
(task, code)
}
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -314,6 +328,12 @@ impl<State> Index<'_, State> {
}); });
self.service.post_encoded("/indexes", body, self.encoder).await self.service.post_encoded("/indexes", body, self.encoder).await
} }
pub(super) async fn _delete(&self) -> (Value, StatusCode) {
let url = format!("/indexes/{}", urlencode(self.uid.as_ref()));
self.service.delete(url).await
}
pub async fn wait_task(&self, update_id: u64) -> Value { pub async fn wait_task(&self, update_id: u64) -> Value {
// try several times to get status, or panic to not wait forever // try several times to get status, or panic to not wait forever
let url = format!("/tasks/{}", update_id); let url = format!("/tasks/{}", update_id);

View File

@ -1,51 +1,50 @@
use crate::common::Server; use crate::common::{shared_does_not_exists_index, Server};
use crate::json; use crate::json;
#[actix_rt::test] #[actix_rt::test]
async fn create_and_delete_index() { async fn create_and_delete_index() {
let server = Server::new().await; let server = Server::new_shared();
let index = server.index("test"); let index = server.unique_index();
let (_response, code) = index.create(None).await; let (response, code) = index.create(None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
index.wait_task(0).await; index.wait_task(response.uid()).await.succeeded();
assert_eq!(index.get().await.1, 200); assert_eq!(index.get().await.1, 200);
let (_response, code) = index.delete().await; let (response, code) = index.delete().await;
assert_eq!(code, 202); assert_eq!(code, 202);
index.wait_task(1).await; index.wait_task(response.uid()).await.succeeded();
assert_eq!(index.get().await.1, 404); assert_eq!(index.get().await.1, 404);
} }
#[actix_rt::test] #[actix_rt::test]
async fn error_delete_unexisting_index() { async fn error_delete_unexisting_index() {
let server = Server::new().await; let index = shared_does_not_exists_index().await;
let index = server.index("test"); let (task, code) = index.delete_index_fail().await;
let (_, code) = index.delete().await;
assert_eq!(code, 202); assert_eq!(code, 202);
let expected_response = json!({ let expected_response = json!({
"message": "Index `test` not found.", "message": "Index `DOES_NOT_EXISTS` not found.",
"code": "index_not_found", "code": "index_not_found",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found" "link": "https://docs.meilisearch.com/errors#index_not_found"
}); });
let response = index.wait_task(0).await; let response = index.wait_task(task.uid()).await;
assert_eq!(response["status"], "failed"); assert_eq!(response["status"], "failed");
assert_eq!(response["error"], expected_response); assert_eq!(response["error"], expected_response);
} }
#[actix_rt::test] #[actix_rt::test]
async fn loop_delete_add_documents() { async fn loop_delete_add_documents() {
let server = Server::new().await; let server = Server::new_shared();
let index = server.index("test"); let index = server.unique_index();
let documents = json!([{"id": 1, "field1": "hello"}]); let documents = json!([{"id": 1, "field1": "hello"}]);
let mut tasks = Vec::new(); let mut tasks = Vec::new();
for _ in 0..50 { for _ in 0..50 {