mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 03:55:07 +08:00
Add tests on every platform and fix clippy errors
This commit is contained in:
parent
d34d7cbc37
commit
f80ea24d2b
46
.github/workflows/rust.yml
vendored
46
.github/workflows/rust.yml
vendored
@ -13,12 +13,44 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
|
name: Tests on ${{ matrix.os }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-18.04, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Build
|
- name: Run cargo test
|
||||||
run: cargo build --verbose
|
uses: actions-rs/cargo@v1
|
||||||
- name: Run tests
|
with:
|
||||||
run: cargo test --verbose
|
command: test
|
||||||
|
args: --locked --release
|
||||||
|
|
||||||
|
# We don't run test on Windows since we get the following error: There is not enough space on the disk.
|
||||||
|
build-on-windows:
|
||||||
|
name: Build on windows-latest
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Run cargo test
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: build
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Run Clippy
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
components: clippy
|
||||||
|
- name: Run cargo clippy
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clippy
|
||||||
|
args: --all-targets -- --deny warnings
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
status = ['tests']
|
status = [
|
||||||
|
'Tests on ubuntu-18.04',
|
||||||
|
'Tests on macos-latest',
|
||||||
|
'Build on windows-latest',
|
||||||
|
'Run Clippy'
|
||||||
|
]
|
||||||
# 3 hours timeout
|
# 3 hours timeout
|
||||||
timeout-sec = 10800
|
timeout-sec = 10800
|
||||||
|
@ -162,7 +162,7 @@ impl Index {
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (_id, obkv) in self.documents(&rtxn, documents_ids)? {
|
for (_id, obkv) in self.documents(&rtxn, documents_ids)? {
|
||||||
let document = make_document(&all_attributes, &fields_ids_map, obkv.clone())?;
|
let document = make_document(&all_attributes, &fields_ids_map, obkv)?;
|
||||||
let formatted = compute_formatted(
|
let formatted = compute_formatted(
|
||||||
&fields_ids_map,
|
&fields_ids_map,
|
||||||
obkv,
|
obkv,
|
||||||
|
@ -197,7 +197,7 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
|
|||||||
.map_err(|e| IndexError::Error(e.into()))
|
.map_err(|e| IndexError::Error(e.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
*self.processing.write().await = Some(meta.index_uuid().clone());
|
*self.processing.write().await = Some(*meta.index_uuid());
|
||||||
let result = get_result(self, meta, data).await;
|
let result = get_result(self, meta, data).await;
|
||||||
*self.processing.write().await = None;
|
*self.processing.write().await = None;
|
||||||
|
|
||||||
|
@ -13,16 +13,16 @@ use uuid::Uuid;
|
|||||||
use crate::helpers::EnvSizer;
|
use crate::helpers::EnvSizer;
|
||||||
use crate::index_controller::updates::*;
|
use crate::index_controller::updates::*;
|
||||||
|
|
||||||
type BEU64 = heed::zerocopy::U64<heed::byteorder::BE>;
|
type Beu64 = heed::zerocopy::U64<heed::byteorder::BE>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UpdateStore<M, N, E> {
|
pub struct UpdateStore<M, N, E> {
|
||||||
pub env: Env,
|
pub env: Env,
|
||||||
pending_meta: Database<OwnedType<BEU64>, SerdeJson<Enqueued<M>>>,
|
pending_meta: Database<OwnedType<Beu64>, SerdeJson<Enqueued<M>>>,
|
||||||
pending: Database<OwnedType<BEU64>, SerdeJson<PathBuf>>,
|
pending: Database<OwnedType<Beu64>, SerdeJson<PathBuf>>,
|
||||||
processed_meta: Database<OwnedType<BEU64>, SerdeJson<Processed<M, N>>>,
|
processed_meta: Database<OwnedType<Beu64>, SerdeJson<Processed<M, N>>>,
|
||||||
failed_meta: Database<OwnedType<BEU64>, SerdeJson<Failed<M, E>>>,
|
failed_meta: Database<OwnedType<Beu64>, SerdeJson<Failed<M, E>>>,
|
||||||
aborted_meta: Database<OwnedType<BEU64>, SerdeJson<Aborted<M>>>,
|
aborted_meta: Database<OwnedType<Beu64>, SerdeJson<Aborted<M>>>,
|
||||||
processing: Arc<RwLock<Option<Processing<M>>>>,
|
processing: Arc<RwLock<Option<Processing<M>>>>,
|
||||||
notification_sender: mpsc::Sender<()>,
|
notification_sender: mpsc::Sender<()>,
|
||||||
/// A lock on the update loop. This is meant to prevent a snapshot to occur while an update is
|
/// A lock on the update loop. This is meant to prevent a snapshot to occur while an update is
|
||||||
@ -176,7 +176,7 @@ where
|
|||||||
// asking for the id and registering it so other update registering
|
// asking for the id and registering it so other update registering
|
||||||
// will be forced to wait for a new write txn.
|
// will be forced to wait for a new write txn.
|
||||||
let update_id = self.new_update_id(&wtxn)?;
|
let update_id = self.new_update_id(&wtxn)?;
|
||||||
let update_key = BEU64::new(update_id);
|
let update_key = Beu64::new(update_id);
|
||||||
|
|
||||||
let meta = Enqueued::new(meta, update_id, index_uuid);
|
let meta = Enqueued::new(meta, update_id, index_uuid);
|
||||||
self.pending_meta.put(&mut wtxn, &update_key, &meta)?;
|
self.pending_meta.put(&mut wtxn, &update_key, &meta)?;
|
||||||
@ -295,7 +295,7 @@ where
|
|||||||
/// Returns the update associated meta or `None` if the update doesn't exist.
|
/// Returns the update associated meta or `None` if the update doesn't exist.
|
||||||
pub fn meta(&self, update_id: u64) -> heed::Result<Option<UpdateStatus<M, N, E>>> {
|
pub fn meta(&self, update_id: u64) -> heed::Result<Option<UpdateStatus<M, N, E>>> {
|
||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
let key = BEU64::new(update_id);
|
let key = Beu64::new(update_id);
|
||||||
|
|
||||||
if let Some(ref meta) = *self.processing.read() {
|
if let Some(ref meta) = *self.processing.read() {
|
||||||
if meta.id() == update_id {
|
if meta.id() == update_id {
|
||||||
@ -331,7 +331,7 @@ where
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn abort_update(&self, update_id: u64) -> heed::Result<Option<Aborted<M>>> {
|
pub fn abort_update(&self, update_id: u64) -> heed::Result<Option<Aborted<M>>> {
|
||||||
let mut wtxn = self.env.write_txn()?;
|
let mut wtxn = self.env.write_txn()?;
|
||||||
let key = BEU64::new(update_id);
|
let key = Beu64::new(update_id);
|
||||||
|
|
||||||
// We cannot abort an update that is currently being processed.
|
// We cannot abort an update that is currently being processed.
|
||||||
if self.pending_meta.first(&wtxn)?.map(|(key, _)| key.get()) == Some(update_id) {
|
if self.pending_meta.first(&wtxn)?.map(|(key, _)| key.get()) == Some(update_id) {
|
||||||
@ -369,7 +369,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (id, aborted) in &aborted_updates {
|
for (id, aborted) in &aborted_updates {
|
||||||
let key = BEU64::new(*id);
|
let key = Beu64::new(*id);
|
||||||
self.aborted_meta.put(&mut wtxn, &key, &aborted)?;
|
self.aborted_meta.put(&mut wtxn, &key, &aborted)?;
|
||||||
self.pending_meta.delete(&mut wtxn, &key)?;
|
self.pending_meta.delete(&mut wtxn, &key)?;
|
||||||
self.pending.delete(&mut wtxn, &key)?;
|
self.pending.delete(&mut wtxn, &key)?;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
use actix_web::get;
|
use actix_web::get;
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
@ -33,7 +32,7 @@ impl From<IndexStats> for IndexStatsResponse {
|
|||||||
Self {
|
Self {
|
||||||
number_of_documents: stats.number_of_documents,
|
number_of_documents: stats.number_of_documents,
|
||||||
is_indexing: stats.is_indexing,
|
is_indexing: stats.is_indexing,
|
||||||
fields_distribution: BTreeMap::from_iter(stats.fields_distribution.into_iter()),
|
fields_distribution: stats.fields_distribution.into_iter().collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl Index<'_> {
|
|||||||
update_id as u64
|
update_id as u64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create<'a>(&'a self, primary_key: Option<&str>) -> (Value, StatusCode) {
|
pub async fn create(& self, primary_key: Option<&str>) -> (Value, StatusCode) {
|
||||||
let body = json!({
|
let body = json!({
|
||||||
"uid": self.uid,
|
"uid": self.uid,
|
||||||
"primaryKey": primary_key,
|
"primaryKey": primary_key,
|
||||||
|
@ -44,7 +44,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a view to an index. There is no guarantee that the index exists.
|
/// Returns a view to an index. There is no guarantee that the index exists.
|
||||||
pub fn index<'a>(&'a self, uid: impl AsRef<str>) -> Index<'a> {
|
pub fn index(& self, uid: impl AsRef<str>) -> Index<'_> {
|
||||||
Index {
|
Index {
|
||||||
uid: encode(uid.as_ref()),
|
uid: encode(uid.as_ref()),
|
||||||
service: &self.service,
|
service: &self.service,
|
||||||
|
@ -8,13 +8,13 @@ pub struct Service(pub Data);
|
|||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
pub async fn post(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||||
let mut app = test::init_service(create_app!(&self.0, true)).await;
|
let app = test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
.set_json(&body)
|
.set_json(&body)
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
@ -28,14 +28,14 @@ impl Service {
|
|||||||
url: impl AsRef<str>,
|
url: impl AsRef<str>,
|
||||||
body: impl AsRef<str>,
|
body: impl AsRef<str>,
|
||||||
) -> (Value, StatusCode) {
|
) -> (Value, StatusCode) {
|
||||||
let mut app = test::init_service(create_app!(&self.0, true)).await;
|
let app = test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
.set_payload(body.as_ref().to_string())
|
.set_payload(body.as_ref().to_string())
|
||||||
.insert_header(("content-type", "application/json"))
|
.insert_header(("content-type", "application/json"))
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
@ -44,10 +44,10 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
pub async fn get(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||||
let mut app = test::init_service(create_app!(&self.0, true)).await;
|
let app = test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
let req = test::TestRequest::get().uri(url.as_ref()).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
@ -56,13 +56,13 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
pub async fn put(&self, url: impl AsRef<str>, body: Value) -> (Value, StatusCode) {
|
||||||
let mut app = test::init_service(create_app!(&self.0, true)).await;
|
let app = test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::put()
|
let req = test::TestRequest::put()
|
||||||
.uri(url.as_ref())
|
.uri(url.as_ref())
|
||||||
.set_json(&body)
|
.set_json(&body)
|
||||||
.to_request();
|
.to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
@ -71,10 +71,10 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
pub async fn delete(&self, url: impl AsRef<str>) -> (Value, StatusCode) {
|
||||||
let mut app = test::init_service(create_app!(&self.0, true)).await;
|
let app = test::init_service(create_app!(&self.0, true)).await;
|
||||||
|
|
||||||
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
let req = test::TestRequest::delete().uri(url.as_ref()).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&app, req).await;
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
|
||||||
let body = test::read_body(res).await;
|
let body = test::read_body(res).await;
|
||||||
|
@ -55,10 +55,8 @@ async fn list_multiple_indexes() {
|
|||||||
assert_eq!(arr.len(), 2);
|
assert_eq!(arr.len(), 2);
|
||||||
assert!(arr
|
assert!(arr
|
||||||
.iter()
|
.iter()
|
||||||
.find(|entry| entry["uid"] == "test" && entry["primaryKey"] == Value::Null)
|
.any(|entry| entry["uid"] == "test" && entry["primaryKey"] == Value::Null));
|
||||||
.is_some());
|
|
||||||
assert!(arr
|
assert!(arr
|
||||||
.iter()
|
.iter()
|
||||||
.find(|entry| entry["uid"] == "test1" && entry["primaryKey"] == "key")
|
.any(|entry| entry["uid"] == "test1" && entry["primaryKey"] == "key"));
|
||||||
.is_some());
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ async fn perform_snapshot() {
|
|||||||
let snapshot_path = snapshot_dir
|
let snapshot_path = snapshot_dir
|
||||||
.path()
|
.path()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.join(format!("db.snapshot"));
|
.join("db.snapshot".to_string());
|
||||||
|
|
||||||
let options = Opt {
|
let options = Opt {
|
||||||
import_snapshot: Some(snapshot_path),
|
import_snapshot: Some(snapshot_path),
|
||||||
|
Loading…
Reference in New Issue
Block a user