diff --git a/rust/lancedb/src/table/dataset.rs b/rust/lancedb/src/table/dataset.rs index 2dd3b7189..e37c3fc9f 100644 --- a/rust/lancedb/src/table/dataset.rs +++ b/rust/lancedb/src/table/dataset.rs @@ -518,6 +518,10 @@ mod tests { let wrapper = DatasetConsistencyWrapper::new_latest(ds, Some(Duration::from_millis(200))); + // Freeze `cached_at` on the mock clock so a slow external write below can't + // expire the TTL before the explicit advance_by() does (flake on loaded CI). + clock::pin(); + // Populate the cache let v1 = wrapper.get().await.unwrap().version().version; assert_eq!(v1, 1); diff --git a/rust/lancedb/src/utils/background_cache.rs b/rust/lancedb/src/utils/background_cache.rs index bdf033fec..e493fd4c6 100644 --- a/rust/lancedb/src/utils/background_cache.rs +++ b/rust/lancedb/src/utils/background_cache.rs @@ -329,6 +329,15 @@ pub mod clock { }); } + /// Start mock time at the current instant if not already pinned. + pub fn pin() { + MOCK_NOW.with(|mock| { + if mock.get().is_none() { + mock.set(Some(Instant::now())); + } + }); + } + #[allow(dead_code)] pub fn clear_mock() { MOCK_NOW.with(|mock| mock.set(None));