mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-06-06 04:05:37 +00:00
Merge pull request #5579 from martin-g/faster-index-update_index-it-tests
perf: Faster index::update_index IT tests
This commit is contained in:
commit
283f516e15
@ -29,6 +29,10 @@ impl<'a> Index<'a, Owned> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_encoder(&self, encoder: Encoder) -> Index<'a, Owned> {
|
||||||
|
Index { uid: self.uid.clone(), service: self.service, encoder, marker: PhantomData }
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn load_test_set(&self) -> u64 {
|
pub async fn load_test_set(&self) -> u64 {
|
||||||
let url = format!("/indexes/{}/documents", urlencode(self.uid.as_ref()));
|
let url = format!("/indexes/{}/documents", urlencode(self.uid.as_ref()));
|
||||||
let (response, code) = self
|
let (response, code) = self
|
||||||
@ -290,6 +294,20 @@ impl Index<'_, Shared> {
|
|||||||
}
|
}
|
||||||
(task, code)
|
(task, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_index_fail(&self, primary_key: Option<&str>) -> (Value, StatusCode) {
|
||||||
|
let (mut task, code) = self._update(primary_key).await;
|
||||||
|
if code.is_success() {
|
||||||
|
task = self.wait_task(task.uid()).await;
|
||||||
|
if task.is_success() {
|
||||||
|
panic!(
|
||||||
|
"`update_index_fail` succeeded: {}",
|
||||||
|
serde_json::to_string_pretty(&task).unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(task, code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -333,6 +351,14 @@ 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 _update(&self, primary_key: Option<&str>) -> (Value, StatusCode) {
|
||||||
|
let body = json!({
|
||||||
|
"primaryKey": primary_key,
|
||||||
|
});
|
||||||
|
let url = format!("/indexes/{}", urlencode(self.uid.as_ref()));
|
||||||
|
self.service.patch_encoded(url, body, self.encoder).await
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn _delete(&self) -> (Value, StatusCode) {
|
pub(super) async fn _delete(&self) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}", urlencode(self.uid.as_ref()));
|
let url = format!("/indexes/{}", urlencode(self.uid.as_ref()));
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
|
@ -2,28 +2,26 @@ use time::format_description::well_known::Rfc3339;
|
|||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::common::encoder::Encoder;
|
use crate::common::encoder::Encoder;
|
||||||
use crate::common::Server;
|
use crate::common::{shared_does_not_exists_index, shared_index_with_documents, Server};
|
||||||
use crate::json;
|
use crate::json;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn update_primary_key() {
|
async fn update_primary_key() {
|
||||||
let server = Server::new().await;
|
let server = Server::new_shared();
|
||||||
let index = server.index("test");
|
let index = server.unique_index();
|
||||||
let (_, code) = index.create(None).await;
|
let (task, code) = index.create(None).await;
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
index.wait_task(task.uid()).await.succeeded();
|
||||||
|
|
||||||
let (task, _status_code) = index.update(Some("primary")).await;
|
let (task, _status_code) = index.update(Some("primary")).await;
|
||||||
|
index.wait_task(task.uid()).await.succeeded();
|
||||||
let response = index.wait_task(task.uid()).await;
|
|
||||||
|
|
||||||
assert_eq!(response["status"], "succeeded");
|
|
||||||
|
|
||||||
let (response, code) = index.get().await;
|
let (response, code) = index.get().await;
|
||||||
|
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
|
|
||||||
assert_eq!(response["uid"], "test");
|
assert_eq!(response["uid"], index.uid);
|
||||||
assert!(response.get("createdAt").is_some());
|
assert!(response.get("createdAt").is_some());
|
||||||
assert!(response.get("updatedAt").is_some());
|
assert!(response.get("updatedAt").is_some());
|
||||||
|
|
||||||
@ -39,24 +37,23 @@ async fn update_primary_key() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn create_and_update_with_different_encoding() {
|
async fn create_and_update_with_different_encoding() {
|
||||||
let server = Server::new().await;
|
let server = Server::new_shared();
|
||||||
let index = server.index_with_encoder("test", Encoder::Gzip);
|
let index = server.unique_index_with_encoder(Encoder::Gzip);
|
||||||
let (_, code) = index.create(None).await;
|
let (create_task, code) = index.create(None).await;
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
index.wait_task(create_task.uid()).await.succeeded();
|
||||||
|
|
||||||
let index = server.index_with_encoder("test", Encoder::Brotli);
|
let index = index.with_encoder(Encoder::Brotli);
|
||||||
let (task, _status_code) = index.update(Some("primary")).await;
|
let (task, _status_code) = index.update(Some("primary")).await;
|
||||||
|
|
||||||
let response = index.wait_task(task.uid()).await;
|
index.wait_task(task.uid()).await.succeeded();
|
||||||
|
|
||||||
assert_eq!(response["status"], "succeeded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn update_nothing() {
|
async fn update_nothing() {
|
||||||
let server = Server::new().await;
|
let server = Server::new_shared();
|
||||||
let index = server.index("test");
|
let index = server.unique_index();
|
||||||
let (task1, code) = index.create(None).await;
|
let (task1, code) = index.create(None).await;
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
@ -67,35 +64,20 @@ async fn update_nothing() {
|
|||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
|
||||||
let response = index.wait_task(task2.uid()).await;
|
index.wait_task(task2.uid()).await.succeeded();
|
||||||
|
|
||||||
assert_eq!(response["status"], "succeeded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn error_update_existing_primary_key() {
|
async fn error_update_existing_primary_key() {
|
||||||
let server = Server::new().await;
|
let index = shared_index_with_documents().await;
|
||||||
let index = server.index("test");
|
|
||||||
let (_response, code) = index.create(Some("id")).await;
|
let (update_task, code) = index.update_index_fail(Some("primary")).await;
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
let response = index.wait_task(update_task.uid()).await.failed();
|
||||||
let documents = json!([
|
|
||||||
{
|
|
||||||
"id": "11",
|
|
||||||
"content": "foobar"
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
index.add_documents(documents, None).await;
|
|
||||||
|
|
||||||
let (task, code) = index.update(Some("primary")).await;
|
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
|
||||||
|
|
||||||
let response = index.wait_task(task.uid()).await;
|
|
||||||
|
|
||||||
let expected_response = json!({
|
let expected_response = json!({
|
||||||
"message": "Index `test`: Index already has a primary key: `id`.",
|
"message": format!("Index `{}`: Index already has a primary key: `id`.", index.uid),
|
||||||
"code": "index_primary_key_already_exists",
|
"code": "index_primary_key_already_exists",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#index_primary_key_already_exists"
|
"link": "https://docs.meilisearch.com/errors#index_primary_key_already_exists"
|
||||||
@ -106,15 +88,15 @@ async fn error_update_existing_primary_key() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn error_update_unexisting_index() {
|
async fn error_update_unexisting_index() {
|
||||||
let server = Server::new().await;
|
let index = shared_does_not_exists_index().await;
|
||||||
let (task, code) = server.index("test").update(None).await;
|
let (task, code) = index.update_index_fail(Some("my-primary-key")).await;
|
||||||
|
|
||||||
assert_eq!(code, 202);
|
assert_eq!(code, 202);
|
||||||
|
|
||||||
let response = server.index("test").wait_task(task.uid()).await;
|
let response = index.wait_task(task.uid()).await.failed();
|
||||||
|
|
||||||
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user