From 7587f8e0a43d6ec71ad8b291c5f2a2e962ec813d Mon Sep 17 00:00:00 2001 From: Troy Hoffman Date: Tue, 28 Jul 2026 11:27:26 +0200 Subject: [PATCH] test(db): truncate expected timestamp to the fence's microsecond precision `fence_starts_closed_and_opens_on_advance` asserted that `verified_through()` returns exactly the `DateTime` handed to `advance()`. That round-trip is lossy: `ReplicaFence` stores the fence as unix microseconds in an `AtomicI64`, so any sub-microsecond remainder in the input is dropped. The assertion therefore depends on the host clock's resolution. Where `Utc::now()` yields microsecond precision the remainder is always zero and the test passes; on platforms where it yields nanoseconds (Linux) the test fails whenever the sampled instant is not a whole microsecond: assertion `left == right` failed left: Some(2026-07-28T09:13:17.081354Z) right: Some(2026-07-28T09:13:17.081354808Z) Build the expected value at the fence's own precision - via `DateTime::from_timestamp_micros(Utc::now().timestamp_micros())` - so the comparison tests the fence's behaviour rather than the clock's resolution. Truncating `ts` at the source also keeps the neighbouring inclusive-boundary assertions (`covers(ts)` and `covers(ts +/- 1s)`) meaningful, since they exercise the same value that was stored. Test-only change. Production callers reach the fence through `covers()`, which is a comparison rather than an equality check and is unaffected by the truncation. Signed-off-by: Troy Hoffman --- crates/buzz-db/src/replica_fence.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/buzz-db/src/replica_fence.rs b/crates/buzz-db/src/replica_fence.rs index 03bc1c77f0..f6edc1afe6 100644 --- a/crates/buzz-db/src/replica_fence.rs +++ b/crates/buzz-db/src/replica_fence.rs @@ -521,7 +521,11 @@ mod tests { assert!(fence.verified_through().is_none(), "must start closed"); assert!(!fence.covers(Utc::now() - chrono::Duration::days(365))); - let ts = Utc::now(); + // The fence stores unix micros, so a nanosecond-precision clock (as on + // Linux) does not round-trip through `advance`. Truncate to the + // fence's own precision before comparing. + let ts = DateTime::from_timestamp_micros(Utc::now().timestamp_micros()) + .expect("now is representable in micros"); fence.advance(ts); assert_eq!(fence.verified_through(), Some(ts)); assert!(fence.covers(ts - chrono::Duration::seconds(1)));