Merge pull request #5572 from martin-g/faster-stats-it-tests

perf: Faster IT tests - stats.rs
This commit is contained in:
Tamo 2025-05-19 12:44:08 +00:00 committed by GitHub
commit 8a0bf24ed5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,10 +1,11 @@
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 stats() { async fn stats() {
let server = Server::new().await; let server = Server::new_shared();
let index = server.index("test"); let index = server.unique_index();
let (task, code) = index.create(Some("id")).await; let (task, code) = index.create(Some("id")).await;
assert_eq!(code, 202); assert_eq!(code, 202);
@ -15,7 +16,7 @@ async fn stats() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["numberOfDocuments"], 0); assert_eq!(response["numberOfDocuments"], 0);
assert!(response["isIndexing"] == false); assert_eq!(response["isIndexing"], false);
assert!(response["fieldDistribution"].as_object().unwrap().is_empty()); assert!(response["fieldDistribution"].as_object().unwrap().is_empty());
let documents = json!([ let documents = json!([
@ -31,7 +32,6 @@ async fn stats() {
let (response, code) = index.add_documents(documents, None).await; let (response, code) = index.add_documents(documents, None).await;
assert_eq!(code, 202); assert_eq!(code, 202);
assert_eq!(response["taskUid"], 1);
index.wait_task(response.uid()).await.succeeded(); index.wait_task(response.uid()).await.succeeded();
@ -39,7 +39,7 @@ async fn stats() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["numberOfDocuments"], 2); assert_eq!(response["numberOfDocuments"], 2);
assert!(response["isIndexing"] == false); assert_eq!(response["isIndexing"], false);
assert_eq!(response["fieldDistribution"]["id"], 2); assert_eq!(response["fieldDistribution"]["id"], 2);
assert_eq!(response["fieldDistribution"]["name"], 1); assert_eq!(response["fieldDistribution"]["name"], 1);
assert_eq!(response["fieldDistribution"]["age"], 1); assert_eq!(response["fieldDistribution"]["age"], 1);
@ -47,11 +47,11 @@ async fn stats() {
#[actix_rt::test] #[actix_rt::test]
async fn error_get_stats_unexisting_index() { async fn error_get_stats_unexisting_index() {
let server = Server::new().await; let index = shared_does_not_exists_index().await;
let (response, code) = server.index("test").stats().await; let (response, code) = index.stats().await;
let expected_response = json!({ let expected_response = json!({
"message": "Index `test` not found.", "message": format!("Index `{}` not found.", index.uid),
"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"