mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-18 17:11:15 +08:00
Add a test to check that we can abort an indexation
This commit is contained in:
parent
6603437cb1
commit
fc03e53615
@ -1196,6 +1196,7 @@ pub(crate) mod tests {
|
|||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
use crate::documents::DocumentsBatchReader;
|
use crate::documents::DocumentsBatchReader;
|
||||||
|
use crate::error::{Error, InternalError};
|
||||||
use crate::index::{DEFAULT_MIN_WORD_LEN_ONE_TYPO, DEFAULT_MIN_WORD_LEN_TWO_TYPOS};
|
use crate::index::{DEFAULT_MIN_WORD_LEN_ONE_TYPO, DEFAULT_MIN_WORD_LEN_TWO_TYPOS};
|
||||||
use crate::update::{self, IndexDocuments, IndexDocumentsConfig, IndexerConfig, Settings};
|
use crate::update::{self, IndexDocuments, IndexDocumentsConfig, IndexerConfig, Settings};
|
||||||
use crate::{db_snap, Index};
|
use crate::{db_snap, Index};
|
||||||
@ -1287,6 +1288,40 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn aborting_indexation() {
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
use std::sync::atomic::Ordering::Relaxed;
|
||||||
|
|
||||||
|
let index = TempIndex::new();
|
||||||
|
let mut wtxn = index.inner.write_txn().unwrap();
|
||||||
|
|
||||||
|
let should_abort = AtomicBool::new(false);
|
||||||
|
let builder = IndexDocuments::new(
|
||||||
|
&mut wtxn,
|
||||||
|
&index.inner,
|
||||||
|
&index.indexer_config,
|
||||||
|
index.index_documents_config.clone(),
|
||||||
|
|_| (),
|
||||||
|
|| should_abort.load(Relaxed),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let (builder, user_error) = builder
|
||||||
|
.add_documents(documents!([
|
||||||
|
{ "id": 1, "name": "kevin" },
|
||||||
|
{ "id": 2, "name": "bob", "age": 20 },
|
||||||
|
{ "id": 2, "name": "bob", "age": 20 },
|
||||||
|
]))
|
||||||
|
.unwrap();
|
||||||
|
user_error.unwrap();
|
||||||
|
|
||||||
|
should_abort.store(true, Relaxed);
|
||||||
|
let err = builder.execute().unwrap_err();
|
||||||
|
|
||||||
|
assert!(matches!(err, Error::InternalError(InternalError::AbortedIndexation)));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn initial_field_distribution() {
|
fn initial_field_distribution() {
|
||||||
let index = TempIndex::new();
|
let index = TempIndex::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user