Add task deletion tests where the same task is deleted twice

This commit is contained in:
Loïc Lecrenier 2022-10-15 11:38:43 +02:00 committed by Clément Renault
parent f32b973945
commit 8defad6c38
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
5 changed files with 124 additions and 0 deletions

View File

@ -830,6 +830,10 @@ impl IndexScheduler {
let processing_tasks = &self.processing_tasks.read().unwrap().1; let processing_tasks = &self.processing_tasks.read().unwrap().1;
// TODO: Lo: Take the intersection of `matched_tasks` and `all_tasks` first,
// so that we end up with the correct count for `deleted_tasks` (the value returned
// by this function). Related snapshot test:
// `task_deletion_delete_same_task_twice/task_deletion_processed.snap`
let mut to_delete_tasks = matched_tasks - processing_tasks; let mut to_delete_tasks = matched_tasks - processing_tasks;
to_delete_tasks -= enqueued_tasks; to_delete_tasks -= enqueued_tasks;

View File

@ -791,6 +791,47 @@ mod tests {
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "task_deletion_processed"); snapshot!(snapshot_index_scheduler(&index_scheduler), name: "task_deletion_processed");
} }
#[test]
fn task_deletion_delete_same_task_twice() {
let (index_scheduler, handle) = IndexScheduler::test(true);
let (file0, documents_count0) = sample_documents(&index_scheduler, 0, 0);
let (file1, documents_count1) = sample_documents(&index_scheduler, 1, 1);
let to_enqueue = [
replace_document_import_task("catto", None, 0, documents_count0),
replace_document_import_task("doggo", Some("bone"), 1, documents_count1),
];
for task in to_enqueue {
let _ = index_scheduler.register(task).unwrap();
}
file0.persist().unwrap();
file1.persist().unwrap();
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "initial_tasks_enqueued");
handle.wait_till(Breakpoint::AfterProcessing);
// first addition of documents should be successful
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "initial_tasks_processed");
// Now we delete the first task multiple times in a row
for _ in 0..2 {
index_scheduler
.register(KindWithContent::TaskDeletion {
query: "test_query".to_owned(),
tasks: RoaringBitmap::from_iter(&[0]),
})
.unwrap();
}
for _ in 0..2 {
handle.wait_till(Breakpoint::AfterProcessing);
}
// The three deletion tasks are marked as succeeded, and all their details say that one
// task has been deleted. Is this the correct behaviour? Probably not!
snapshot!(snapshot_index_scheduler(&index_scheduler), name: "task_deletion_processed");
}
#[test] #[test]
fn document_addition() { fn document_addition() {
let (index_scheduler, handle) = IndexScheduler::test(true); let (index_scheduler, handle) = IndexScheduler::test(true);

View File

@ -0,0 +1,25 @@
---
source: index-scheduler/src/lib.rs
---
### Autobatching Enabled = true
### Processing Tasks:
[]
----------------------------------------------------------------------
### All Tasks:
0 {uid: 0, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 1, allow_index_creation: true }}
1 {uid: 1, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 1, allow_index_creation: true }}
----------------------------------------------------------------------
### Status:
enqueued [0,1,]
----------------------------------------------------------------------
### Kind:
"documentImport" [0,1,]
----------------------------------------------------------------------
### Index Tasks:
catto [0,]
doggo [1,]
----------------------------------------------------------------------
### Index Mapper:
[]
----------------------------------------------------------------------

View File

@ -0,0 +1,26 @@
---
source: index-scheduler/src/lib.rs
---
### Autobatching Enabled = true
### Processing Tasks:
[]
----------------------------------------------------------------------
### All Tasks:
0 {uid: 0, status: succeeded, details: { received_documents: 1, indexed_documents: 1 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 1, allow_index_creation: true }}
1 {uid: 1, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 1, allow_index_creation: true }}
----------------------------------------------------------------------
### Status:
enqueued [1,]
succeeded [0,]
----------------------------------------------------------------------
### Kind:
"documentImport" [0,1,]
----------------------------------------------------------------------
### Index Tasks:
catto [0,]
doggo [1,]
----------------------------------------------------------------------
### Index Mapper:
["catto"]
----------------------------------------------------------------------

View File

@ -0,0 +1,28 @@
---
source: index-scheduler/src/lib.rs
---
### Autobatching Enabled = true
### Processing Tasks:
[]
----------------------------------------------------------------------
### All Tasks:
1 {uid: 1, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 1, allow_index_creation: true }}
2 {uid: 2, status: succeeded, details: { matched_tasks: 1, deleted_tasks: Some(1), original_query: "test_query" }, kind: TaskDeletion { query: "test_query", tasks: RoaringBitmap<[0]> }}
3 {uid: 3, status: succeeded, details: { matched_tasks: 1, deleted_tasks: Some(1), original_query: "test_query" }, kind: TaskDeletion { query: "test_query", tasks: RoaringBitmap<[0]> }}
----------------------------------------------------------------------
### Status:
enqueued [1,]
succeeded [2,3,]
----------------------------------------------------------------------
### Kind:
"documentImport" [1,]
"taskDeletion" [2,3,]
----------------------------------------------------------------------
### Index Tasks:
catto []
doggo [1,]
----------------------------------------------------------------------
### Index Mapper:
["catto"]
----------------------------------------------------------------------