From ceca9b2e9a3d4da94f93da33a22af3fe2c004c49 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:55:43 +0530 Subject: [PATCH] test(rotortree): poll for the checkpoint meta file instead of racing wait_for_checkpoint only sees a checkpoint that finishes after the call. The inserts start the background checkpoint, so it can finish first and the wait times out. Poll for data/checkpoint.meta, which write_meta renames into place, so the tests no longer depend on timing. --- crates/rotortree/tests/storage_integration.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/rotortree/tests/storage_integration.rs b/crates/rotortree/tests/storage_integration.rs index 7b31236..7666b2a 100644 --- a/crates/rotortree/tests/storage_integration.rs +++ b/crates/rotortree/tests/storage_integration.rs @@ -26,6 +26,21 @@ fn manual_config(dir: &std::path::Path) -> RotorTreeConfig { } } +/// Poll for the background checkpoint's meta file. `wait_for_checkpoint` +/// only sees a checkpoint that finishes after the call, and the one the +/// inserts started may already be done by then. +fn wait_for_checkpoint_meta(dir: &std::path::Path) -> bool { + let meta = dir.join("data").join("checkpoint.meta"); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5); + while !meta.exists() { + if std::time::Instant::now() >= deadline { + return false; + } + std::thread::sleep(std::time::Duration::from_millis(1)); + } + true +} + #[test] fn open_empty_close_reopen() { // given @@ -591,7 +606,7 @@ fn checkpoint_every_n_entries() { tree.insert(leaf(i)).unwrap(); } - assert!(tree.wait_for_checkpoint(std::time::Duration::from_secs(5))); + assert!(wait_for_checkpoint_meta(dir.path())); let root = tree.root(); tree.flush().unwrap(); @@ -622,7 +637,7 @@ fn checkpoint_memory_threshold() { let leaves: Vec = (0..200u32).map(leaf).collect(); tree.insert_many(&leaves).unwrap(); - assert!(tree.wait_for_checkpoint(std::time::Duration::from_secs(5))); + assert!(wait_for_checkpoint_meta(dir.path())); let root = tree.root(); tree.flush().unwrap();