Skip to content

test(ingester): make RFC0008.8 latency test deterministic via virtual clock - #197

Merged
jensholdgaard merged 2 commits into
mainfrom
fix/rfc0008-8-latency-test-deterministic-clock
Jun 14, 2026
Merged

test(ingester): make RFC0008.8 latency test deterministic via virtual clock#197
jensholdgaard merged 2 commits into
mainfrom
fix/rfc0008-8-latency-test-deterministic-clock

Conversation

@jensholdgaard

@jensholdgaard jensholdgaard commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Problem

rfc0008_8_p99_latency_tracks_batch_window was flaky on main. It asserted a strict 3-way monotonic ordering of three wall-clock P99s (p99(10) < p99(50) < p99(150)), which is non-deterministic — the per-flush fixed overhead dominates the smallest window and any sample can spike, flipping the order:

The coverage job's red is what surfaced as "CI failing on main" (the required job currently passes; the coverage job fails reliably under instrumentation).

Fix (maintainer-chosen: deterministic virtual clock)

Run the test under a paused virtual clock (#[tokio::test(start_paused = true)], enabled by tokio's test-util dev feature). tokio auto-advances to the next pending timer when the runtime is idle, so the only time that elapses is the coordinator's own tokio::time::sleep(window). The real fsync (offloaded to spawn_blocking) runs in wall-clock time but does not advance the virtual clock, so measuring with tokio::time::Instant yields the commit's batch wait exactly — no scheduler/instrumentation jitter.

Invariants (CLAUDE.md §3 / §6.2)

This strengthens the contract, it does not weaken it (§6.2 — tests are specifications):

  • Ack latency now equals the configured window exactly and scales 1:1 across the spec's real {10, 100, 1000} ms values (the prior {10, 50, 150} "documented deviation" is gone — virtual time is free).
  • A per-record-fsync impl would ack at ≈ 0 regardless of the window; that latency is the window is exactly "the window dominates" (§3.4).
  • Batching itself (appends_per_sync ≫ 1) stays pinned counter-exactly by the sibling test.

Verification

Ran the rewritten test 6× locally — deterministic (exact equality holds each time), ~0.02 s. Full ourios-ingester test crate, cargo fmt --check, and cargo clippy --all-targets --all-features -D warnings all clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Improved test reliability for batched-fsync validation using deterministic virtual clock measurements instead of latency-based assertions.
  • Documentation

    • Updated acceptance criteria documentation to reflect new deterministic test approach.
  • Chores

    • Updated development dependencies for enhanced testing utilities.

… clock

`rfc0008_8_p99_latency_tracks_batch_window` asserted a strict 3-way
monotonic ordering of three *wall-clock* P99 measurements
(`p99(10) < p99(50) < p99(150)`). That ordering is non-deterministic: on a
loaded or instrumented runner the per-flush fixed overhead dominates the
smallest window and any sample can spike, flipping the order. It flaked the
required `cargo test` job on #193 (`[164, 491, 311]`) and the
`continue-on-error` coverage job on #196 (`[482, 53, 154]`, llvm-cov
instrumentation inflating the 10 ms window to 482 ms).

Rewrite it to run under a paused virtual clock (`#[tokio::test(start_paused
= true)]`, enabled by tokio's `test-util` dev feature). tokio auto-advances
to the next pending timer when the runtime is idle, so the only time that
elapses is the coordinator's own `tokio::time::sleep(window)`; the real
fsync (offloaded to `spawn_blocking`) runs in wall-clock time but does not
advance the virtual clock. Measuring with `tokio::time::Instant` therefore
yields the commit's batch wait exactly, with zero jitter.

This strengthens the contract rather than weakening it (§6.2): a batch of
commits fired together all ride one window, so ack latency *equals* the
configured window and scales 1:1 across the spec's real `{10, 100, 1000}`
ms values (now free of wall-clock cost — the prior `{10, 50, 150}`
deviation is gone). A per-record-fsync impl would ack at ≈ 0 regardless of
the window. Batching itself (`appends_per_sync ≫ 1`) stays pinned
counter-exactly by the sibling test. Approach chosen by the maintainer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jensholdgaard
jensholdgaard requested a review from Copilot June 14, 2026 01:19
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 51ce3e18-4ce9-41e2-b4dc-d113e379a993

📥 Commits

Reviewing files that changed from the base of the PR and between 3f3c987 and f219ab3.

📒 Files selected for processing (3)
  • crates/ourios-ingester/Cargo.toml
  • crates/ourios-ingester/tests/rfc0008_8_batched_fsync.rs
  • docs/rfcs/0008-wal.md

📝 Walkthrough

Walkthrough

RFC0008.8's batched-fsync test is rewritten from a P99 wall-clock latency check with ±30% tolerance to a deterministic assertion under a paused Tokio virtual clock, where each commit's ack latency must equal the configured wal_batch_window_ms exactly. The test-util Tokio feature is added to dev-dependencies, and the RFC docs are updated to match.

Changes

RFC0008.8 Deterministic Batch-Window Test

Layer / File(s) Summary
Enable tokio test-util feature
crates/ourios-ingester/Cargo.toml
Adds test-util to the tokio dev-dependency feature list, enabling start_paused = true in Tokio tests.
Rewrite RFC0008.8 test with paused virtual clock
crates/ourios-ingester/tests/rfc0008_8_batched_fsync.rs
Removes p99_ms, measure_latencies, and rfc0008_8_p99_latency_tracks_batch_window; adds rfc0008_8_ack_latency_tracks_the_batch_window under #[tokio::test(start_paused = true)], which spawns concurrent commits and asserts each ack-latency equals the configured batch window exactly for {10, 100, 1000} ms. Swaps std::time::Instant import for Duration.
Update RFC0008.8 acceptance criteria and test strategy
docs/rfcs/0008-wal.md
Replaces the P99 wall-clock ±30% tolerance acceptance criteria with the deterministic paused-clock formulation, and updates the test-strategy section to match.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • jensholdgaard/ourios#191: Adds the CommitCoordinator and group-commit behavior that the rewritten RFC0008.8 test in this PR exercises deterministically.
  • jensholdgaard/ourios#65: Previously updated the RFC0008.8 batched-fsync acceptance criteria in docs/rfcs/0008-wal.md, the same section this PR revises.

Poem

🐇 Hop, hop — no more wall-clock fuzz,
The virtual clock is paused just because!
Ten, hundred, thousand — each window lands right,
No P99 guessing, the latency's tight.
A deterministic bunny approves this delight! 🕰️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: converting a flaky wall-clock P99 latency test into a deterministic virtual-clock-based test.
Description check ✅ Passed The PR description comprehensively covers the problem (flakiness), the solution (virtual clock), verification, and invariants. All template sections are addressed with substantial detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rfc0008-8-latency-test-deterministic-clock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR rewrites the RFC0008.8 ingester latency test to eliminate flakiness by running it under Tokio’s paused virtual clock, making the “batch window dominates” timing assertion deterministic (and independent of CI jitter/coverage instrumentation).

Changes:

  • Replace the wall-clock P99-based latency test with a virtual-time-based test that asserts deterministic batch-window waiting behavior.
  • Update the RFC0008.8 batched-fsync test documentation and implementation to use tokio::time::Instant.
  • Enable Tokio’s test-util feature in ourios-ingester dev-dependencies to support #[tokio::test(start_paused = true)].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/ourios-ingester/tests/rfc0008_8_batched_fsync.rs Replaces flaky wall-clock P99 latency sampling with a deterministic virtual-clock assertion for batch-window wait time.
crates/ourios-ingester/Cargo.toml Adds Tokio test-util feature in dev-dependencies to enable start_paused in tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/ourios-ingester/tests/rfc0008_8_batched_fsync.rs
Copilot flagged a spec/test mismatch on #197: the RFC0008.8 §5 scenario
still described measuring wall-clock P99 ack latency over a 10 s sample
within a ±30 % tolerance, but the test now asserts exact ack-latency
equality under a paused virtual clock.

Update the scenario (and the §5 summary) to the virtual-clock formulation:
a batch of commits fired together under a paused clock each ack at exactly
the configured window (deterministic, no jitter) — the window dominates,
not per-record fsync. The contract is unchanged (window dominates,
appends_per_sync ≫ 1, §3.4 holds); only the measurement method is
restated, superseding the non-deterministic wall-clock-P99 formulation.
Approach approved by the maintainer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jensholdgaard
jensholdgaard merged commit cf3b58b into main Jun 14, 2026
13 checks passed
@jensholdgaard
jensholdgaard deleted the fix/rfc0008-8-latency-test-deterministic-clock branch June 14, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants