mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 20:45:06 +08:00
457a473b72
* Fix error code of the "duplicate index found" error * Use the content of the ProcessingTasks in the tasks cancelation system * Change the missing_filters error code into missing_task_filters * WIP Introduce the invalid_task_uid error code * Use more precise error codes/message for the task routes + Allow star operator in delete/cancel tasks + rename originalQuery to originalFilters + Display error/canceled_by in task view even when they are = null + Rename task filter fields by using their plural forms + Prepare an error code for canceledBy filter + Only return global tasks if the API key action `index.*` is there * Add canceledBy task filter * Update tests following task API changes * Rename original_query to original_filters everywhere * Update more insta-snap tests * Make clippy happy They're a happy clip now. * Make rustfmt happy >:-( * Fix Index name parsing error message to fit the specification * Bump milli version to 0.35.1 * Fix the new error messages * fix the error messages and add tests * rename the error codes for the sake of consistency * refactor the way we send the cli informations + add the analytics for the config file and ssl usage * Apply suggestions from code review Co-authored-by: Clément Renault <clement@meilisearch.com> * add a comment over the new infos structure * reformat, sorry @kero * Store analytics for the documents deletions * Add analytics on all the settings * Spawn threads with names * Spawn rayon threads with names * update the distinct attributes to the spec update * update the analytics on the search route * implements the analytics on the health and version routes * Fix task details serialization * Add the question mark to the task deletion query filter * Add the question mark to the task cancelation query filter * Fix tests * add analytics on the task route * Add all the missing fields of the new task query type * Create a new analytics for the task deletion * Create a new analytics for the task creation * batch the tasks seen events * Update the finite pagination analytics * add the analytics of the swap-indexes route * Stop removing the DB when failing to read it * Rename originalFilters into originalFilters * Rename matchedDocuments into providedIds * Add `workflow_dispatch` to flaky.yml * Bump grenad to 0.4.4 * Bump milli to version v0.37.0 * Don't multiply total memory returned by sysinfo anymore sysinfo now returns bytes rather than KB * Add a dispatch to the publish binaries workflow * Fix publish release CI * Don't use gold but the default linker * Always display details for the indexDeletion task * Fix the insta tests * refactorize the whole test suite 1. Make a call to assert_internally_consistent automatically when snapshoting the scheduler. There is no point in snapshoting something broken and expect the dumb humans to notice. 2. Replace every possible call to assert_internally_consistent by a snapshot of the scheduler. It takes as many lines and ensure we never change something without noticing in any tests ever. 3. Name every snapshots: it's easier to debug when something goes wrong and easier to review in general. 4. Stop skipping breakpoints, it's too easy to miss something. Now you must explicitely show which path is the scheduler supposed to use. 5. Add a timeout on the channel.recv, it eases the process of writing tests, now when something file you get a failure instead of a deadlock. * rebase on release-v0.30 * makes clippy happy * update the snapshots after a rebase * try to remove the flakyness of the failing test * Add more analytics on the ranking rules positions * Update the dump test to check for the dumpUid dumpCreation task details * send the ranking rules as a string because amplitude is too dumb to process an array as a single value * Display a null dumpUid until we computed the dump itself on disk * Update tests * Check if the master key is missing before returning an error Co-authored-by: Loïc Lecrenier <loic.lecrenier@me.com> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Co-authored-by: Kerollmops <clement@meilisearch.com> Co-authored-by: ManyTheFish <many@meilisearch.com> Co-authored-by: Tamo <tamo@meilisearch.com> Co-authored-by: Louis Dureuil <louis@meilisearch.com>
319 lines
11 KiB
Rust
319 lines
11 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use once_cell::sync::Lazy;
|
|
use serde_json::{json, Value};
|
|
|
|
use crate::common::Server;
|
|
|
|
static DEFAULT_SETTINGS_VALUES: Lazy<HashMap<&'static str, Value>> = Lazy::new(|| {
|
|
let mut map = HashMap::new();
|
|
map.insert("displayed_attributes", json!(["*"]));
|
|
map.insert("searchable_attributes", json!(["*"]));
|
|
map.insert("filterable_attributes", json!([]));
|
|
map.insert("distinct_attribute", json!(Value::Null));
|
|
map.insert(
|
|
"ranking_rules",
|
|
json!(["words", "typo", "proximity", "attribute", "sort", "exactness"]),
|
|
);
|
|
map.insert("stop_words", json!([]));
|
|
map.insert("synonyms", json!({}));
|
|
map.insert(
|
|
"faceting",
|
|
json!({
|
|
"maxValuesPerFacet": json!(100),
|
|
}),
|
|
);
|
|
map.insert(
|
|
"pagination",
|
|
json!({
|
|
"maxTotalHits": json!(1000),
|
|
}),
|
|
);
|
|
map
|
|
});
|
|
|
|
#[actix_rt::test]
|
|
async fn get_settings_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let (response, code) = server.index("test").settings().await;
|
|
assert_eq!(code, 404, "{}", response)
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn get_settings() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.create(None).await;
|
|
index.wait_task(0).await;
|
|
let (response, code) = index.settings().await;
|
|
assert_eq!(code, 200);
|
|
let settings = response.as_object().unwrap();
|
|
assert_eq!(settings.keys().len(), 11);
|
|
assert_eq!(settings["displayedAttributes"], json!(["*"]));
|
|
assert_eq!(settings["searchableAttributes"], json!(["*"]));
|
|
assert_eq!(settings["filterableAttributes"], json!([]));
|
|
assert_eq!(settings["sortableAttributes"], json!([]));
|
|
assert_eq!(settings["distinctAttribute"], json!(null));
|
|
assert_eq!(
|
|
settings["rankingRules"],
|
|
json!(["words", "typo", "proximity", "attribute", "sort", "exactness"])
|
|
);
|
|
assert_eq!(settings["stopWords"], json!([]));
|
|
assert_eq!(
|
|
settings["faceting"],
|
|
json!({
|
|
"maxValuesPerFacet": 100,
|
|
})
|
|
);
|
|
assert_eq!(
|
|
settings["pagination"],
|
|
json!({
|
|
"maxTotalHits": 1000,
|
|
})
|
|
);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn error_update_settings_unknown_field() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, code) = index.update_settings(json!({"foo": 12})).await;
|
|
assert_eq!(code, 400);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn test_partial_update() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, _code) = index.update_settings(json!({"displayedAttributes": ["foo"]})).await;
|
|
index.wait_task(0).await;
|
|
let (response, code) = index.settings().await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response["displayedAttributes"], json!(["foo"]));
|
|
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
|
|
|
let (_response, _) = index.update_settings(json!({"searchableAttributes": ["bar"]})).await;
|
|
index.wait_task(1).await;
|
|
|
|
let (response, code) = index.settings().await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response["displayedAttributes"], json!(["foo"]));
|
|
assert_eq!(response["searchableAttributes"], json!(["bar"]));
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn error_delete_settings_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, code) = index.delete_settings().await;
|
|
assert_eq!(code, 202);
|
|
|
|
let response = index.wait_task(0).await;
|
|
|
|
assert_eq!(response["status"], "failed");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn reset_all_settings() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
|
|
let documents = json!([
|
|
{
|
|
"id": 1,
|
|
"name": "curqui",
|
|
"age": 99
|
|
}
|
|
]);
|
|
|
|
let (response, code) = index.add_documents(documents, None).await;
|
|
assert_eq!(code, 202);
|
|
assert_eq!(response["taskUid"], 0);
|
|
index.wait_task(0).await;
|
|
|
|
index
|
|
.update_settings(json!({"displayedAttributes": ["name", "age"], "searchableAttributes": ["name"], "stopWords": ["the"], "filterableAttributes": ["age"], "synonyms": {"puppy": ["dog", "doggo", "potat"] }}))
|
|
.await;
|
|
index.wait_task(1).await;
|
|
let (response, code) = index.settings().await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response["displayedAttributes"], json!(["name", "age"]));
|
|
assert_eq!(response["searchableAttributes"], json!(["name"]));
|
|
assert_eq!(response["stopWords"], json!(["the"]));
|
|
assert_eq!(response["synonyms"], json!({"puppy": ["dog", "doggo", "potat"] }));
|
|
assert_eq!(response["filterableAttributes"], json!(["age"]));
|
|
|
|
index.delete_settings().await;
|
|
index.wait_task(2).await;
|
|
|
|
let (response, code) = index.settings().await;
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response["displayedAttributes"], json!(["*"]));
|
|
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
|
assert_eq!(response["stopWords"], json!([]));
|
|
assert_eq!(response["filterableAttributes"], json!([]));
|
|
assert_eq!(response["synonyms"], json!({}));
|
|
|
|
let (response, code) = index.get_document(1, None).await;
|
|
assert_eq!(code, 200);
|
|
assert!(response.as_object().unwrap().get("age").is_some());
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn update_setting_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (_response, code) = index.update_settings(json!({})).await;
|
|
assert_eq!(code, 202);
|
|
let response = index.wait_task(0).await;
|
|
assert_eq!(response["status"], "succeeded");
|
|
let (_response, code) = index.get().await;
|
|
assert_eq!(code, 200);
|
|
index.delete_settings().await;
|
|
let response = index.wait_task(1).await;
|
|
assert_eq!(response["status"], "succeeded");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn error_update_setting_unexisting_index_invalid_uid() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test##! ");
|
|
let (response, code) = index.update_settings(json!({})).await;
|
|
assert_eq!(code, 400);
|
|
|
|
let expected = json!({
|
|
"message": "`test##! ` is not a valid index uid. Index uid can be an integer or a string containing only alphanumeric characters, hyphens (-) and underscores (_).",
|
|
"code": "invalid_index_uid",
|
|
"type": "invalid_request",
|
|
"link": "https://docs.meilisearch.com/errors#invalid_index_uid"});
|
|
|
|
assert_eq!(response, expected);
|
|
}
|
|
|
|
macro_rules! test_setting_routes {
|
|
($($setting:ident $write_method:ident), *) => {
|
|
$(
|
|
mod $setting {
|
|
use crate::common::Server;
|
|
use super::DEFAULT_SETTINGS_VALUES;
|
|
|
|
#[actix_rt::test]
|
|
async fn get_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let url = format!("/indexes/test/settings/{}",
|
|
stringify!($setting)
|
|
.chars()
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
.collect::<String>());
|
|
let (_response, code) = server.service.get(url).await;
|
|
assert_eq!(code, 404);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn update_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let url = format!("/indexes/test/settings/{}",
|
|
stringify!($setting)
|
|
.chars()
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
.collect::<String>());
|
|
let (response, code) = server.service.$write_method(url, serde_json::Value::Null).await;
|
|
assert_eq!(code, 202, "{}", response);
|
|
server.index("").wait_task(0).await;
|
|
let (response, code) = server.index("test").get().await;
|
|
assert_eq!(code, 200, "{}", response);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn delete_unexisting_index() {
|
|
let server = Server::new().await;
|
|
let url = format!("/indexes/test/settings/{}",
|
|
stringify!($setting)
|
|
.chars()
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
.collect::<String>());
|
|
let (_, code) = server.service.delete(url).await;
|
|
assert_eq!(code, 202);
|
|
let response = server.index("").wait_task(0).await;
|
|
assert_eq!(response["status"], "failed");
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn get_default() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
let (response, code) = index.create(None).await;
|
|
assert_eq!(code, 202, "{}", response);
|
|
index.wait_task(0).await;
|
|
let url = format!("/indexes/test/settings/{}",
|
|
stringify!($setting)
|
|
.chars()
|
|
.map(|c| if c == '_' { '-' } else { c })
|
|
.collect::<String>());
|
|
let (response, code) = server.service.get(url).await;
|
|
assert_eq!(code, 200, "{}", response);
|
|
let expected = DEFAULT_SETTINGS_VALUES.get(stringify!($setting)).unwrap();
|
|
assert_eq!(expected, &response);
|
|
}
|
|
}
|
|
)*
|
|
};
|
|
}
|
|
|
|
test_setting_routes!(
|
|
filterable_attributes put,
|
|
displayed_attributes put,
|
|
searchable_attributes put,
|
|
distinct_attribute put,
|
|
stop_words put,
|
|
ranking_rules put,
|
|
synonyms put,
|
|
pagination patch,
|
|
faceting patch
|
|
);
|
|
|
|
#[actix_rt::test]
|
|
async fn error_set_invalid_ranking_rules() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
index.create(None).await;
|
|
|
|
let (_response, _code) =
|
|
index.update_settings(json!({ "rankingRules": [ "manyTheFish"]})).await;
|
|
index.wait_task(1).await;
|
|
let (response, code) = index.get_task(1).await;
|
|
|
|
assert_eq!(code, 200);
|
|
assert_eq!(response["status"], "failed");
|
|
|
|
let expected_error = json!({
|
|
"message": r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules."#,
|
|
"code": "invalid_ranking_rule",
|
|
"type": "invalid_request",
|
|
"link": "https://docs.meilisearch.com/errors#invalid_ranking_rule"
|
|
});
|
|
|
|
assert_eq!(response["error"], expected_error);
|
|
}
|
|
|
|
#[actix_rt::test]
|
|
async fn set_and_reset_distinct_attribute_with_dedicated_route() {
|
|
let server = Server::new().await;
|
|
let index = server.index("test");
|
|
|
|
let (_response, _code) = index.update_distinct_attribute(json!("test")).await;
|
|
index.wait_task(0).await;
|
|
|
|
let (response, _) = index.get_distinct_attribute().await;
|
|
|
|
assert_eq!(response, "test");
|
|
|
|
index.update_distinct_attribute(json!(null)).await;
|
|
|
|
index.wait_task(1).await;
|
|
|
|
let (response, _) = index.get_distinct_attribute().await;
|
|
|
|
assert_eq!(response, json!(null));
|
|
}
|