From 0940f0e4f46651a3bf459901d58f118a7c1b4563 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 14 May 2025 17:40:15 +0200 Subject: [PATCH] add a test --- crates/index-scheduler/src/scheduler/test.rs | 27 ++++++++++++++++++++ crates/index-scheduler/src/test_utils.rs | 7 +++++ 2 files changed, 34 insertions(+) diff --git a/crates/index-scheduler/src/scheduler/test.rs b/crates/index-scheduler/src/scheduler/test.rs index 84112de08..f13af9f87 100644 --- a/crates/index-scheduler/src/scheduler/test.rs +++ b/crates/index-scheduler/src/scheduler/test.rs @@ -929,3 +929,30 @@ fn create_and_list_index() { ] "###); } + +#[test] +fn test_scheduler_doesnt_run_with_zero_batched_tasks() { + let (index_scheduler, mut handle) = IndexScheduler::test_with_custom_config(vec![], |config| { + config.max_number_of_batched_tasks = 0; + None + }); + + handle.scheduler_is_down(); + + // Register a task + index_scheduler + .register( + KindWithContent::IndexCreation { index_uid: S("doggos"), primary_key: None }, + None, + false, + ) + .unwrap(); + snapshot!(snapshot_index_scheduler(&index_scheduler), name: "registered_task"); + + handle.scheduler_is_down(); + + // If we restart the scheduler, it should run properly. + let (index_scheduler, mut handle) = handle.restart(index_scheduler, true, vec![], |_| None); + handle.advance_n_successful_batches(1); + snapshot!(snapshot_index_scheduler(&index_scheduler), name: "after_restart"); +} diff --git a/crates/index-scheduler/src/test_utils.rs b/crates/index-scheduler/src/test_utils.rs index 0d44b3c81..bbdf0c500 100644 --- a/crates/index-scheduler/src/test_utils.rs +++ b/crates/index-scheduler/src/test_utils.rs @@ -118,6 +118,9 @@ impl IndexScheduler { (versioning::VERSION_MAJOR, versioning::VERSION_MINOR, versioning::VERSION_PATCH) }); + // If the number of batched tasks is 0, the scheduler will not run and we can't do the init check. + let skip_init = options.max_number_of_batched_tasks == 0; + std::fs::create_dir_all(&options.auth_path).unwrap(); let auth_env = open_auth_store_env(&options.auth_path).unwrap(); let index_scheduler = @@ -126,7 +129,11 @@ impl IndexScheduler { // To be 100% consistent between all test we're going to start the scheduler right now // and ensure it's in the expected starting state. let breakpoint = match receiver.recv_timeout(std::time::Duration::from_secs(10)) { + Ok(b) if skip_init => { + panic!("The scheduler was not supposed to start, but it did: {b:?}.") + } Ok(b) => b, + Err(_) if skip_init => (Init, false), Err(RecvTimeoutError::Timeout) => { panic!("The scheduler seems to be waiting for a new task while your test is waiting for a breakpoint.") }