Repository navigation
test(node): cover prefetch record_served through the live cdn/client/v1 serve loop (#900) - #909
Conversation
…v1 serve loop (#900) The demand-quality auto-throttle's served-bytes numerator is fed by PrefetchEngine::note_served_if_prefetched, called from the accepted-voucher branch of collect_voucher in the client serve handler. Until now both halves of the credit contract were tested only in isolation (tag-on-acquire e2e + tag->credit unit); the wiring through the real serve loop had no coverage. Add an e2e test: node B prefetch-acquires a blob from upstream A (tagging it as prefetch content), then a separate client C performs a real paid cdn/client/v1 pull of that blob from B. The pull drives note_served_if_prefetched from the live ClientHandler, moving the served/acquired demand-quality ratio from a zero baseline to exactly 1.0 (the whole blob acquired and served back). A negative control then serves an untagged blob (one B reactively pulled on a cache miss, never prefetch-acquired) through the same live handler and asserts the ratio is unchanged, pinning the acquired.contains gate through the real serve path rather than just that some credit fires. Both directions were falsification-checked: disabling the production note_served_if_prefetched call fails the positive assertion, and removing the acquired.contains gate fails the negative control. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a new integration test prefetch_acquired_blob_credits_served_through_serve_loop and a helper function cache_with_blobs in crates/node/tests/node_origin_pull.rs to verify that serving a prefetch-acquired blob correctly updates the demand-quality ratio, while serving an untagged blob does not. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds an end-to-end integration test to ensure prefetch-acquired blobs are credited as “served” via the real cdn/client/v1 serve loop (i.e., the production ClientHandler path), covering the previously untested wiring for demand-quality metrics.
Changes:
- Adds a new multi-node loopback test that prefetch-acquires a blob and then performs a paid
stream_fetchthrough the live client handler, assertingserved/acquiredmoves from 0.0 to exactly 1.0. - Adds a negative-control flow that serves an untagged (reactively populated) blob and asserts the ratio remains unchanged.
- Introduces a small helper to seed a cache with multiple blobs for the upstream node fixture.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.71% (was 85.66%, ▲ +0.05%) — 37080/43262 lines No coverage data for changed Rust files. History
|
What
Closes #900. Adds an end-to-end test that pins the previously-uncovered wiring: a real paid
cdn/client/v1serve of a prefetch-acquired blob drivesPrefetchEngine::note_served_if_prefetchedfrom inside the livecollect_voucherloop (crates/node/src/handlers/client.rs), feeding the demand-qualityserved / acquirednumerator.Until now both halves of the credit contract were tested only in isolation:
prefetch_acquire_pulls_and_records_spendnote_served_credits_only_prefetched_hashesNeither exercised the real serve loop, so a refactor dropping the
attach_prefetch_enginecall, theprefetch_engine.get()guard, or thenote_served_if_prefetchedcall would have gone uncaught.How
Three loopback endpoints:
ClientHandlerover the same cache with the engine attached.stream_fetchpaid pull from B.Positive: after the pull, the ratio moves from a 0.0 baseline to exactly 1.0 (whole blob acquired = denominator, whole blob served back = numerator over both voucher intervals). Asserting the precise value — not just
> 0— catches partial-credit bugs (e.g. crediting only the first 1 MiB interval → ~0.67).Negative control: B reactively pulls a second, untagged blob (plain cache-miss
populate, never prefetch-acquired) and C serves it through the same live handler; the ratio must stay at 1.0. This pins theacquired.containsgate through the real serve path, not just that some credit fires.Verification
node_origin_pullbinary 23/23 pass.note_served_if_prefetchedcall fails the positive assertion; removing theacquired.containsgate (so every served blob credits) drives the ratio to 2.0 and fails the negative control.cargo fmt --check,cargo clippy -p decdn-node --tests, and all pre-commit hooks (fmt/clippy/doc/deny) clean.Test-only; no production code changed.
🤖 Generated with Claude Code