mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +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:
|
||||
tests:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: Tests on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-18.04, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
||||
- name: Run cargo test
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
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
|
||||
timeout-sec = 10800
|
||||
|
@ -162,7 +162,7 @@ impl Index {
|
||||
);
|
||||
|
||||
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(
|
||||
&fields_ids_map,
|
||||
obkv,
|
||||
|
@ -197,7 +197,7 @@ impl<S: IndexStore + Sync + Send> IndexActor<S> {
|
||||
.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;
|
||||
*self.processing.write().await = None;
|
||||
|
||||
|
@ -13,16 +13,16 @@ use uuid::Uuid;
|
||||
use crate::helpers::EnvSizer;
|
||||
use crate::index_controller::updates::*;
|
||||
|
||||
type BEU64 = heed::zerocopy::U64<heed::byteorder::BE>;
|
||||
type Beu64 = heed::zerocopy::U64<heed::byteorder::BE>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UpdateStore<M, N, E> {
|
||||
pub env: Env,
|
||||
pending_meta: Database<OwnedType<BEU64>, SerdeJson<Enqueued<M>>>,
|
||||
pending: Database<OwnedType<BEU64>, SerdeJson<PathBuf>>,
|
||||
processed_meta: Database<OwnedType<BEU64>, SerdeJson<Processed<M, N>>>,
|
||||
failed_meta: Database<OwnedType<BEU64>, SerdeJson<Failed<M, E>>>,
|
||||
aborted_meta: Database<OwnedType<BEU64>, SerdeJson<Aborted<M>>>,
|
||||
pending_meta: Database<OwnedType<Beu64>, SerdeJson<Enqueued<M>>>,
|
||||
pending: Database<OwnedType<Beu64>, SerdeJson<PathBuf>>,
|
||||
processed_meta: Database<OwnedType<Beu64>, SerdeJson<Processed<M, N>>>,
|
||||
failed_meta: Database<OwnedType<Beu64>, SerdeJson<Failed<M, E>>>,
|
||||
aborted_meta: Database<OwnedType<Beu64>, SerdeJson<Aborted<M>>>,
|
||||
processing: Arc<RwLock<Option<Processing<M>>>>,
|
||||
notification_sender: mpsc::Sender<()>,
|
||||
/// 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
|
||||
// will be forced to wait for a new write txn.
|
||||
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);
|
||||
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.
|
||||
pub fn meta(&self, update_id: u64) -> heed::Result<Option<UpdateStatus<M, N, E>>> {
|
||||
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 meta.id() == update_id {
|
||||
@ -331,7 +331,7 @@ where
|
||||
#[allow(dead_code)]
|
||||
pub fn abort_update(&self, update_id: u64) -> heed::Result<Option<Aborted<M>>> {
|
||||
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.
|
||||
if self.pending_meta.first(&wtxn)?.map(|(key, _)| key.get()) == Some(update_id) {
|
||||
@ -369,7 +369,7 @@ where
|
||||
}
|
||||
|
||||
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.pending_meta.delete(&mut wtxn, &key)?;
|
||||
self.pending.delete(&mut wtxn, &key)?;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use actix_web::get;
|
||||
use actix_web::web;
|
||||
@ -33,7 +32,7 @@ impl From<IndexStats> for IndexStatsResponse {
|
||||
Self {
|
||||
number_of_documents: stats.number_of_documents,
|
||||
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
|
||||
}
|
||||
|
||||
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!({
|
||||
"uid": self.uid,
|
||||
"primaryKey": primary_key,
|
||||
|
@ -44,7 +44,7 @@ impl Server {
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
uid: encode(uid.as_ref()),
|
||||
service: &self.service,
|
||||
|
@ -8,13 +8,13 @@ pub struct Service(pub Data);
|
||||
|
||||
impl Service {
|
||||
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()
|
||||
.uri(url.as_ref())
|
||||
.set_json(&body)
|
||||
.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 body = test::read_body(res).await;
|
||||
@ -28,14 +28,14 @@ impl Service {
|
||||
url: impl AsRef<str>,
|
||||
body: 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::post()
|
||||
.uri(url.as_ref())
|
||||
.set_payload(body.as_ref().to_string())
|
||||
.insert_header(("content-type", "application/json"))
|
||||
.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 body = test::read_body(res).await;
|
||||
@ -44,10 +44,10 @@ impl Service {
|
||||
}
|
||||
|
||||
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 res = test::call_service(&mut app, req).await;
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
|
||||
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) {
|
||||
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()
|
||||
.uri(url.as_ref())
|
||||
.set_json(&body)
|
||||
.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 body = test::read_body(res).await;
|
||||
@ -71,10 +71,10 @@ impl Service {
|
||||
}
|
||||
|
||||
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 res = test::call_service(&mut app, req).await;
|
||||
let res = test::call_service(&app, req).await;
|
||||
let status_code = res.status();
|
||||
|
||||
let body = test::read_body(res).await;
|
||||
|
@ -55,10 +55,8 @@ async fn list_multiple_indexes() {
|
||||
assert_eq!(arr.len(), 2);
|
||||
assert!(arr
|
||||
.iter()
|
||||
.find(|entry| entry["uid"] == "test" && entry["primaryKey"] == Value::Null)
|
||||
.is_some());
|
||||
.any(|entry| entry["uid"] == "test" && entry["primaryKey"] == Value::Null));
|
||||
assert!(arr
|
||||
.iter()
|
||||
.find(|entry| entry["uid"] == "test1" && entry["primaryKey"] == "key")
|
||||
.is_some());
|
||||
.any(|entry| entry["uid"] == "test1" && entry["primaryKey"] == "key"));
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ async fn perform_snapshot() {
|
||||
let snapshot_path = snapshot_dir
|
||||
.path()
|
||||
.to_owned()
|
||||
.join(format!("db.snapshot"));
|
||||
.join("db.snapshot".to_string());
|
||||
|
||||
let options = Opt {
|
||||
import_snapshot: Some(snapshot_path),
|
||||
|
Loading…
Reference in New Issue
Block a user