Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Add a test to check that we can abort an indexation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Oct 17, 2022
1 parent 6603437 commit fc03e53
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions milli/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ pub(crate) mod tests {
use tempfile::TempDir;

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::update::{self, IndexDocuments, IndexDocumentsConfig, IndexerConfig, Settings};
use crate::{db_snap, Index};
Expand Down Expand Up @@ -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]
fn initial_field_distribution() {
let index = TempIndex::new();
Expand Down

0 comments on commit fc03e53

Please sign in to comment.