test(db): truncate expected timestamp to the fence's microsecond precision - #3308
Open
troyhoffman-oss wants to merge 1 commit into
Open
test(db): truncate expected timestamp to the fence's microsecond precision#3308troyhoffman-oss wants to merge 1 commit into
troyhoffman-oss wants to merge 1 commit into
Conversation
…ision
`fence_starts_closed_and_opens_on_advance` asserted that
`verified_through()` returns exactly the `DateTime<Utc>` 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 <troy.hoffman@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The commit message has the full reasoning; short version:
fence_starts_closed_and_opens_on_advanceassertsverified_through()returns exactly theDateTime<Utc>passed toadvance().ReplicaFencestores the fence as unix microseconds in anAtomicI64, so that round-trip drops any sub-microsecond remainder — the assertion is really testing the host clock's resolution. It passes whereUtc::now()yields microseconds and fails on Linux, where it yields nanoseconds, whenever the sampled instant is not a whole microsecond.Build the expected value at the fence's own precision instead. Truncating
tsat the source also keeps the neighbouring inclusive-boundary assertions (covers(ts),covers(ts ± 1s)) exercising the value that was actually stored.Test-only. Production callers reach the fence through
covers(), a comparison rather than an equality check, which is unaffected.Testing
cargo test -p buzz-db --libon a Linux host.Before (on
main):After:
Full crate suite, three consecutive runs:
85 passed; 0 failed; 139 ignoredeach time.cargo fmt --checkandcargo clippy -p buzz-db --all-targetsclean.