add test for dump processing order

This commit is contained in:
ad hoc 2022-05-25 14:57:18 +02:00
parent f58507379a
commit 74a1f88d88
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643

View File

@ -536,10 +536,10 @@ mod test {
use super::*; use super::*;
fn gen_task(id: TaskId, index_uid: &str, content: TaskContent) -> Task { fn gen_task(id: TaskId, index_uid: Option<&str>, content: TaskContent) -> Task {
Task { Task {
id, id,
index_uid: Some(IndexUid::new_unchecked(index_uid)), index_uid: index_uid.map(IndexUid::new_unchecked),
content, content,
events: vec![], events: vec![],
} }
@ -548,13 +548,13 @@ mod test {
#[test] #[test]
fn register_updates_multiples_indexes() { fn register_updates_multiples_indexes() {
let mut queue = TaskQueue::default(); let mut queue = TaskQueue::default();
queue.insert(gen_task(0, "test1", TaskContent::IndexDeletion)); queue.insert(gen_task(0, Some("test1"), TaskContent::IndexDeletion));
queue.insert(gen_task(1, "test2", TaskContent::IndexDeletion)); queue.insert(gen_task(1, Some("test2"), TaskContent::IndexDeletion));
queue.insert(gen_task(2, "test2", TaskContent::IndexDeletion)); queue.insert(gen_task(2, Some("test2"), TaskContent::IndexDeletion));
queue.insert(gen_task(3, "test2", TaskContent::IndexDeletion)); queue.insert(gen_task(3, Some("test2"), TaskContent::IndexDeletion));
queue.insert(gen_task(4, "test1", TaskContent::IndexDeletion)); queue.insert(gen_task(4, Some("test1"), TaskContent::IndexDeletion));
queue.insert(gen_task(5, "test1", TaskContent::IndexDeletion)); queue.insert(gen_task(5, Some("test1"), TaskContent::IndexDeletion));
queue.insert(gen_task(6, "test2", TaskContent::IndexDeletion)); queue.insert(gen_task(6, Some("test2"), TaskContent::IndexDeletion));
let test1_tasks = queue let test1_tasks = queue
.head_mut(|tasks| tasks.drain().map(|t| t.id).collect::<Vec<_>>()) .head_mut(|tasks| tasks.drain().map(|t| t.id).collect::<Vec<_>>())
@ -582,16 +582,28 @@ mod test {
documents_count: 0, documents_count: 0,
allow_index_creation: true, allow_index_creation: true,
}; };
queue.insert(gen_task(0, "test1", content.clone())); queue.insert(gen_task(0, Some("test1"), content.clone()));
queue.insert(gen_task(1, "test2", content.clone())); queue.insert(gen_task(1, Some("test2"), content.clone()));
queue.insert(gen_task(2, "test2", TaskContent::IndexDeletion)); queue.insert(gen_task(2, Some("test2"), TaskContent::IndexDeletion));
queue.insert(gen_task(3, "test2", content.clone())); queue.insert(gen_task(3, Some("test2"), content.clone()));
queue.insert(gen_task(4, "test1", content.clone())); queue.insert(gen_task(4, Some("test1"), content.clone()));
queue.insert(gen_task(5, "test1", TaskContent::IndexDeletion)); queue.insert(gen_task(5, Some("test1"), TaskContent::IndexDeletion));
queue.insert(gen_task(6, "test2", content.clone())); queue.insert(gen_task(6, Some("test2"), content.clone()));
queue.insert(gen_task(7, "test1", content)); queue.insert(gen_task(7, Some("test1"), content));
queue.insert(gen_task(
8,
None,
TaskContent::Dump {
uid: "adump".to_owned(),
},
));
let config = SchedulerConfig::default(); let config = SchedulerConfig::default();
// Make sure that the dump is processed before everybody else.
let batch = make_batch(&mut queue, &config);
assert_eq!(batch, Processing::Dump(8));
let batch = make_batch(&mut queue, &config); let batch = make_batch(&mut queue, &config);
assert_eq!(batch, Processing::DocumentAdditions(vec![0, 4])); assert_eq!(batch, Processing::DocumentAdditions(vec![0, 4]));