From 13a72f87576baefe2edcf5e6e0fbcd66762fa243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Mon, 10 Oct 2022 15:51:28 +0200 Subject: [PATCH] Use more complete snapshot tests for the index scheduler --- file-store/src/lib.rs | 10 + index-scheduler/src/lib.rs | 212 ++---------------- index-scheduler/src/snapshot.rs | 2 +- ...scheduler__tests__document_addition-2.snap | 23 ++ ...scheduler__tests__document_addition-3.snap | 24 ++ ...x_scheduler__tests__document_addition.snap | 23 ++ ...task_while_another_task_is_processing.snap | 26 +++ .../index_scheduler__tests__register.snap | 30 +++ ...dex_scheduler__tests__task_deletion-2.snap | 29 +++ ...dex_scheduler__tests__task_deletion-3.snap | 29 +++ ...dex_scheduler__tests__task_deletion-4.snap | 30 +++ ...index_scheduler__tests__task_deletion.snap | 27 +++ index-scheduler/src/task.rs | 2 +- 13 files changed, 273 insertions(+), 194 deletions(-) create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__document_addition-2.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__document_addition-3.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__document_addition.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__insert_task_while_another_task_is_processing.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__register.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-2.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-3.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-4.snap create mode 100644 index-scheduler/src/snapshots/index_scheduler__tests__task_deletion.snap diff --git a/file-store/src/lib.rs b/file-store/src/lib.rs index c125fffed..a9df34288 100644 --- a/file-store/src/lib.rs +++ b/file-store/src/lib.rs @@ -58,6 +58,16 @@ impl FileStore { Ok((uuid, update_file)) } + /// Creates a new temporary update file with the given Uuid. + /// A call to `persist` is needed to persist the file in the database. + pub fn new_update_woth_uuid(&self, uuid: u128) -> Result<(Uuid, File)> { + let file = NamedTempFile::new_in(&self.path)?; + let uuid = Uuid::from_u128(uuid); + let path = self.path.join(uuid.to_string()); + let update_file = File { file, path }; + + Ok((uuid, update_file)) + } /// Returns the file corresponding to the requested uuid. pub fn get_update(&self, uuid: Uuid) -> Result { diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 2c5b7b625..04ffcacd7 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -364,6 +364,10 @@ impl IndexScheduler { pub fn create_update_file(&self) -> Result<(Uuid, File)> { Ok(self.file_store.new_update()?) } + #[cfg(test)] + pub fn create_update_file_with_uuid(&self, uuid: u128) -> Result<(Uuid, File)> { + Ok(self.file_store.new_update_woth_uuid(uuid)?) + } pub fn delete_update_file(&self, uuid: Uuid) -> Result<()> { Ok(self.file_store.delete(uuid)?) @@ -404,26 +408,20 @@ impl IndexScheduler { // 2. Process the tasks let res = self.process_batch(batch); - dbg!(); let mut wtxn = self.env.write_txn()?; - dbg!(); let finished_at = OffsetDateTime::now_utc(); match res { Ok(tasks) => { - dbg!(); for mut task in tasks { task.started_at = Some(started_at); task.finished_at = Some(finished_at); // TODO the info field should've been set by the process_batch function self.update_task(&mut wtxn, &task)?; task.remove_data()?; - dbg!(); } - dbg!(); } // In case of a failure we must get back and patch all the tasks with the error. Err(err) => { - dbg!(); let error: ResponseError = err.into(); for id in ids { let mut task = self.get_task(&wtxn, id)?.ok_or(Error::CorruptedTaskQueue)?; @@ -437,11 +435,8 @@ impl IndexScheduler { } } } - dbg!(); *self.processing_tasks.write().unwrap() = (finished_at, RoaringBitmap::new()); - dbg!(); wtxn.commit()?; - dbg!(); log::info!("A batch of tasks was successfully completed."); #[cfg(test)] @@ -461,7 +456,7 @@ mod tests { use tempfile::TempDir; use uuid::Uuid; - use crate::{assert_smol_debug_snapshot, snapshot::snapshot_index}; + use crate::{assert_smol_debug_snapshot, snapshot::snapshot_index_scheduler}; use super::*; @@ -517,8 +512,7 @@ mod tests { #[test] fn register() { - let (index_scheduler, handle) = IndexScheduler::test(true); - handle.dont_block(); + let (index_scheduler, handle) = IndexScheduler::test(); let kinds = [ KindWithContent::IndexCreation { @@ -529,7 +523,7 @@ mod tests { index_uid: S("catto"), primary_key: None, method: ReplaceDocuments, - content_file: Uuid::new_v4(), + content_file: Uuid::from_u128(0), documents_count: 12, allow_index_creation: true, }, @@ -538,7 +532,7 @@ mod tests { index_uid: S("catto"), primary_key: None, method: ReplaceDocuments, - content_file: Uuid::new_v4(), + content_file: Uuid::from_u128(1), documents_count: 50, allow_index_creation: true, }, @@ -546,7 +540,7 @@ mod tests { index_uid: S("doggo"), primary_key: Some(S("bone")), method: ReplaceDocuments, - content_file: Uuid::new_v4(), + content_file: Uuid::from_u128(2), documents_count: 5000, allow_index_creation: true, }, @@ -563,35 +557,7 @@ mod tests { inserted_tasks.push(task); } - let rtxn = index_scheduler.env.read_txn().unwrap(); - let mut all_tasks = Vec::new(); - for ret in index_scheduler.all_tasks.iter(&rtxn).unwrap() { - all_tasks.push(ret.unwrap().0); - } - - // we can't assert on the content of the tasks because there is the date and uuid that changes everytime. - assert_smol_debug_snapshot!(all_tasks, @"[U32(0), U32(1), U32(2), U32(3), U32(4)]"); - - let mut status = Vec::new(); - for ret in index_scheduler.status.iter(&rtxn).unwrap() { - status.push(ret.unwrap()); - } - - assert_smol_debug_snapshot!(status, @"[(Enqueued, RoaringBitmap<[0, 1, 2, 3, 4]>)]"); - - let mut kind = Vec::new(); - for ret in index_scheduler.kind.iter(&rtxn).unwrap() { - kind.push(ret.unwrap()); - } - - assert_smol_debug_snapshot!(kind, @"[(DocumentAddition, RoaringBitmap<[1, 3, 4]>), (IndexCreation, RoaringBitmap<[0]>), (CancelTask, RoaringBitmap<[2]>)]"); - - let mut index_tasks = Vec::new(); - for ret in index_scheduler.index_tasks.iter(&rtxn).unwrap() { - index_tasks.push(ret.unwrap()); - } - - assert_smol_debug_snapshot!(index_tasks, @r###"[("catto", RoaringBitmap<[0, 1, 3]>), ("doggo", RoaringBitmap<[4]>)]"###); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); } #[test] @@ -608,12 +574,7 @@ mod tests { }) .unwrap(); - let mut tasks = index_scheduler.get_tasks(Query::default()).unwrap(); - tasks.reverse(); - assert_eq!(tasks.len(), 3); - assert_eq!(tasks[0].status, Status::Processing); - assert_eq!(tasks[1].status, Status::Enqueued); - assert_eq!(tasks[2].status, Status::Enqueued); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); } /// We send a lot of tasks but notify the tasks scheduler only once as @@ -720,101 +681,27 @@ mod tests { allow_index_creation: true, }, ]; - for task in to_enqueue { let _ = index_scheduler.register(task).unwrap(); } - let rtxn = index_scheduler.env.read_txn().unwrap(); - let mut all_tasks = Vec::new(); - for ret in index_scheduler.all_tasks.iter(&rtxn).unwrap() { - all_tasks.push(ret.unwrap().0); - } - rtxn.commit().unwrap(); - assert_snapshot!(snapshot_index(&index_scheduler), @r###" - ### Processing Tasks: - [] - ---------------------------------------------------------------------- - ### All Tasks: - 0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} - 1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: e881d224-ed39-4322-87ae-eae5a749b835, documents_count: 12, allow_index_creation: true }} - 2 {uid: 2, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: f21ce9f3-58f4-4bab-813b-ecb0b202d20f, documents_count: 5000, allow_index_creation: true }} - ---------------------------------------------------------------------- - ### Status: - enqueued [0,1,2,] - ---------------------------------------------------------------------- - ### Kind: - {"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,2,] - "indexCreation" [0,] - ---------------------------------------------------------------------- - ### Index Tasks: - catto [0,1,] - doggo [2,] - ---------------------------------------------------------------------- - ### Index Mapper: - [] - ---------------------------------------------------------------------- - "###); - - assert_smol_debug_snapshot!(all_tasks, @"[U32(0), U32(1), U32(2)]"); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); index_scheduler.register(KindWithContent::DeleteTasks { query: "test_query".to_owned(), tasks: vec![0, 1], }); - let rtxn = index_scheduler.env.read_txn().unwrap(); - let task = index_scheduler - .all_tasks - .get(&rtxn, &BEU32::new(3)) - .unwrap() - .unwrap(); - rtxn.commit().unwrap(); - - let rtxn = index_scheduler.env.read_txn().unwrap(); - let mut all_tasks = Vec::new(); - for ret in index_scheduler.all_tasks.iter(&rtxn).unwrap() { - all_tasks.push(ret.unwrap().0); - } - rtxn.commit().unwrap(); - - assert_smol_debug_snapshot!(all_tasks, @"[U32(0), U32(1), U32(2), U32(3)]"); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); handle.wait_till(Breakpoint::BatchCreated); - // the last task, with uid = 3, should be marked as processing - // let processing_tasks = &index_scheduler.processing_tasks.read().unwrap().1; - // assert_smol_debug_snapshot!(processing_tasks, @"RoaringBitmap<[3]>"); - let rtxn = index_scheduler.env.read_txn().unwrap(); - let task = index_scheduler - .all_tasks - .get(&rtxn, &BEU32::new(3)) - .unwrap() - .unwrap(); - rtxn.commit().unwrap(); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); handle.wait_till(Breakpoint::AfterProcessing); - dbg!(); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); - let processing_tasks = &index_scheduler.processing_tasks.read().unwrap().1; - assert_smol_debug_snapshot!(processing_tasks, @"RoaringBitmap<[]>"); - - dbg!(); - - let rtxn = index_scheduler.env.read_txn().unwrap(); - let mut all_tasks = Vec::new(); - for ret in index_scheduler.all_tasks.iter(&rtxn).unwrap() { - all_tasks.push(ret.unwrap().0); - } - rtxn.commit().unwrap(); - - dbg!(); - - assert_smol_debug_snapshot!(all_tasks, @"[U32(0), U32(1), U32(2), U32(3)]"); handle.dont_block(); - // index_scheduler.register(KindWithContent::DocumentClear { index_uid: 0 }); - // index_scheduler.register(KindWithContent::CancelTask { tasks: vec![0] }); - // index_scheduler.register(KindWithContendt::DeleteTasks { tasks: vec![0] }); } #[test] @@ -827,7 +714,7 @@ mod tests { "doggo": "bob" }"#; - let (uuid, mut file) = index_scheduler.create_update_file().unwrap(); + let (uuid, mut file) = index_scheduler.create_update_file_with_uuid(0).unwrap(); let documents_count = document_formats::read_json(content.as_bytes(), file.as_file_mut()).unwrap() as u64; index_scheduler @@ -842,74 +729,15 @@ mod tests { .unwrap(); file.persist().unwrap(); - // After registering the task we should see the update being enqueued - let task = index_scheduler.get_tasks(Query::default()).unwrap(); - assert_json_snapshot!(task, - { "[].enqueuedAt" => "date", "[].startedAt" => "date", "[].finishedAt" => "date", "[].duration" => "duration" } - ,@r###" - [ - { - "uid": 0, - "indexUid": "doggos", - "status": "enqueued", - "type": "documentAddition", - "enqueuedAt": "date" - } - ] - "###); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); handle.wait_till(Breakpoint::BatchCreated); - // Once the task has started being batched it should be marked as processing - let task = index_scheduler.get_tasks(Query::default()).unwrap(); - assert_json_snapshot!(task, - { "[].enqueuedAt" => "date", "[].startedAt" => "date", "[].finishedAt" => "date", "[].duration" => "duration" } - ,@r###" - [ - { - "uid": 0, - "indexUid": "doggos", - "status": "processing", - "type": "documentAddition", - "enqueuedAt": "date", - "startedAt": "date" - } - ] - "###); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); + handle.wait_till(Breakpoint::AfterProcessing); - let task = index_scheduler.get_tasks(Query::default()).unwrap(); - assert_json_snapshot!(task, - { "[].enqueuedAt" => "date", "[].startedAt" => "date", "[].finishedAt" => "date", "[].duration" => "duration" } - ,@r###" - [ - { - "uid": 0, - "indexUid": "doggos", - "status": "succeeded", - "type": "documentAddition", - "details": { - "receivedDocuments": 1, - "indexedDocuments": 1 - }, - "duration": "duration", - "enqueuedAt": "date", - "startedAt": "date", - "finishedAt": "date" - } - ] - "###); - - let doggos = index_scheduler.index("doggos").unwrap(); - - let rtxn = doggos.read_txn().unwrap(); - let documents: Vec<_> = doggos - .all_documents(&rtxn) - .unwrap() - .collect::>() - .unwrap(); - - assert_smol_debug_snapshot!(documents, @r###"[{"id": Number(1), "doggo": String("bob")}]"###); + assert_snapshot!(snapshot_index_scheduler(&index_scheduler)); } #[macro_export] diff --git a/index-scheduler/src/snapshot.rs b/index-scheduler/src/snapshot.rs index 09dcde4d3..7a9ede705 100644 --- a/index-scheduler/src/snapshot.rs +++ b/index-scheduler/src/snapshot.rs @@ -13,7 +13,7 @@ use crate::{ IndexScheduler, Kind, Status, }; -pub fn snapshot_index(scheduler: &IndexScheduler) -> String { +pub fn snapshot_index_scheduler(scheduler: &IndexScheduler) -> String { let IndexScheduler { processing_tasks, file_store: _, diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-2.snap b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-2.snap new file mode 100644 index 000000000..389cc4fe1 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-2.snap @@ -0,0 +1,23 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[0,] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggos", primary_key: Some("id"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 1, allow_index_creation: true }} +---------------------------------------------------------------------- +### Status: +enqueued [0,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [0,] +---------------------------------------------------------------------- +### Index Tasks: +doggos [0,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-3.snap b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-3.snap new file mode 100644 index 000000000..00d0cf005 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition-3.snap @@ -0,0 +1,24 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: succeeded, details: { received_documents: 1, indexed_documents: 1 }, kind: DocumentImport { index_uid: "doggos", primary_key: Some("id"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 1, allow_index_creation: true }} +---------------------------------------------------------------------- +### Status: +enqueued [] +succeeded [0,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [0,] +---------------------------------------------------------------------- +### Index Tasks: +doggos [0,] +---------------------------------------------------------------------- +### Index Mapper: +["doggos"] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__document_addition.snap b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition.snap new file mode 100644 index 000000000..03a2f7e55 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__document_addition.snap @@ -0,0 +1,23 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { received_documents: 1, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggos", primary_key: Some("id"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 1, allow_index_creation: true }} +---------------------------------------------------------------------- +### Status: +enqueued [0,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [0,] +---------------------------------------------------------------------- +### Index Tasks: +doggos [0,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__insert_task_while_another_task_is_processing.snap b/index-scheduler/src/snapshots/index_scheduler__tests__insert_task_while_another_task_is_processing.snap new file mode 100644 index 000000000..b92fd0c61 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__insert_task_while_another_task_is_processing.snap @@ -0,0 +1,26 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[0,] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, kind: Snapshot} +1 {uid: 1, status: enqueued, kind: Snapshot} +2 {uid: 2, status: enqueued, kind: IndexDeletion { index_uid: "doggos" }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,] +---------------------------------------------------------------------- +### Kind: +"indexDeletion" [2,] +"snapshot" [0,1,] +---------------------------------------------------------------------- +### Index Tasks: +doggos [2,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__register.snap b/index-scheduler/src/snapshots/index_scheduler__tests__register.snap new file mode 100644 index 000000000..1e3274683 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__register.snap @@ -0,0 +1,30 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 12, allow_index_creation: true }} +2 {uid: 2, status: enqueued, kind: CancelTask { tasks: [0, 1] }} +3 {uid: 3, status: enqueued, details: { received_documents: 50, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 50, allow_index_creation: true }} +4 {uid: 4, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000002, documents_count: 5000, allow_index_creation: true }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,3,4,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,3,4,] +"indexCreation" [0,] +"cancelTask" [2,] +---------------------------------------------------------------------- +### Index Tasks: +catto [0,1,3,] +doggo [4,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-2.snap b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-2.snap new file mode 100644 index 000000000..bb596cbb5 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-2.snap @@ -0,0 +1,29 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 12, allow_index_creation: true }} +2 {uid: 2, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 5000, allow_index_creation: true }} +3 {uid: 3, status: enqueued, details: { matched_tasks: 2, deleted_tasks: None, original_query: "test_query" }, kind: DeleteTasks { query: "test_query", tasks: [0, 1] }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,3,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,2,] +"indexCreation" [0,] +"deleteTasks" [3,] +---------------------------------------------------------------------- +### Index Tasks: +catto [0,1,] +doggo [2,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-3.snap b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-3.snap new file mode 100644 index 000000000..754f07564 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-3.snap @@ -0,0 +1,29 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[3,] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 12, allow_index_creation: true }} +2 {uid: 2, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 5000, allow_index_creation: true }} +3 {uid: 3, status: enqueued, details: { matched_tasks: 2, deleted_tasks: None, original_query: "test_query" }, kind: DeleteTasks { query: "test_query", tasks: [0, 1] }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,3,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,2,] +"indexCreation" [0,] +"deleteTasks" [3,] +---------------------------------------------------------------------- +### Index Tasks: +catto [0,1,] +doggo [2,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-4.snap b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-4.snap new file mode 100644 index 000000000..0b2da8931 --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion-4.snap @@ -0,0 +1,30 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 12, allow_index_creation: true }} +2 {uid: 2, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 5000, allow_index_creation: true }} +3 {uid: 3, status: succeeded, details: { matched_tasks: 2, deleted_tasks: Some(0), original_query: "test_query" }, kind: DeleteTasks { query: "test_query", tasks: [0, 1] }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,] +succeeded [3,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,2,] +"indexCreation" [0,] +"deleteTasks" [3,] +---------------------------------------------------------------------- +### Index Tasks: +catto [0,1,] +doggo [2,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion.snap b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion.snap new file mode 100644 index 000000000..38971952b --- /dev/null +++ b/index-scheduler/src/snapshots/index_scheduler__tests__task_deletion.snap @@ -0,0 +1,27 @@ +--- +source: index-scheduler/src/lib.rs +expression: snapshot_index_scheduler(&index_scheduler) +--- +### Processing Tasks: +[] +---------------------------------------------------------------------- +### All Tasks: +0 {uid: 0, status: enqueued, details: { primary_key: Some("mouse") }, kind: IndexCreation { index_uid: "catto", primary_key: Some("mouse") }} +1 {uid: 1, status: enqueued, details: { received_documents: 12, indexed_documents: 0 }, kind: DocumentImport { index_uid: "catto", primary_key: None, method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000000, documents_count: 12, allow_index_creation: true }} +2 {uid: 2, status: enqueued, details: { received_documents: 5000, indexed_documents: 0 }, kind: DocumentImport { index_uid: "doggo", primary_key: Some("bone"), method: ReplaceDocuments, content_file: 00000000-0000-0000-0000-000000000001, documents_count: 5000, allow_index_creation: true }} +---------------------------------------------------------------------- +### Status: +enqueued [0,1,2,] +---------------------------------------------------------------------- +### Kind: +{"documentImport":{"method":"ReplaceDocuments","allow_index_creation":true}} [1,2,] +"indexCreation" [0,] +---------------------------------------------------------------------- +### Index Tasks: +catto [0,1,] +doggo [2,] +---------------------------------------------------------------------- +### Index Mapper: +[] +---------------------------------------------------------------------- + diff --git a/index-scheduler/src/task.rs b/index-scheduler/src/task.rs index 40c1473a0..4429d0e7e 100644 --- a/index-scheduler/src/task.rs +++ b/index-scheduler/src/task.rs @@ -317,7 +317,7 @@ impl KindWithContent { todo!() } KindWithContent::CancelTask { .. } => { - todo!() + None // TODO: check correctness of this return value } KindWithContent::DeleteTasks { query, tasks } => Some(Details::DeleteTasks { matched_tasks: tasks.len(),