Skip to content

test(cache): cross-pod in-flight staging e2e - #1361

Merged
kalbasit merged 3 commits into
mainfrom
test-cache-cross-pod-in-flight
Jun 8, 2026
Merged

kalbasit merged 3 commits into
mainfrom
test-cache-cross-pod-in-flight

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner

End-to-end verification for in-flight NAR staging (group 13). Adds
InflightStagingCrossPodServe to the distributed suite: with staging enabled
(non-CDC, distributed Redis lock, shared store), numInstances replicas
concurrently pull the same large NAR during its download and each must receive
a complete, byte-correct NAR with no truncation. Verified against Redis
(NCPS_ENABLE_REDIS_TESTS=1).

Zero-overhead (feature disabled, and enabled-but-uncontended) is covered
deterministically by the group-5 producer unit tests.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kalbasit, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 57 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3016b59e-611c-448b-a4ae-4fd858623f03

📥 Commits

Reviewing files that changed from the base of the PR and between 25ab29a and ae79ba6.

📒 Files selected for processing (2)
  • pkg/cache/cache.go
  • pkg/cache/cache_distributed_test.go
📝 Walkthrough

Walkthrough

This PR adds a new distributed concurrency test that validates NAR retrieval across multiple cache instances sharing a database and Redis-based locks during in-flight staging. The test uses a delayed upstream handler to force download overlap, performs concurrent GetNar calls, and asserts byte-exact results on every instance.

Changes

In-Flight Staging Cross-Pod Test

Layer / File(s) Summary
In-flight staging cross-pod concurrency test
pkg/cache/cache_distributed_test.go
Added bytes import for byte comparison, registered InflightStagingCrossPodServe subtest in runDistributedTestSuite, and implemented testInflightStagingCrossPodServe to validate concurrent GetNar calls across multiple cache instances with shared DB/storage and Redis locks return identical byte-correct NARs while tracking per-instance successes and errors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size:L, merge-stack

Poem

🐰 A test for the ages, with caches so bright,
Multiple pods serving NAR in the night,
Each byte-perfect match, no truncation in sight,
The hare hops with joy at your coverage height! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test(cache): cross-pod in-flight staging e2e' clearly and concisely summarizes the main addition: an end-to-end test for cross-pod in-flight NAR staging in the cache package.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the new test, its configuration (distributed Redis lock, shared store, staging enabled), and expected behavior (byte-correct NAR delivery with no truncation).
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.


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

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new integration test, testInflightStagingCrossPodServe, to verify the cross-pod fast path with in-flight NAR staging enabled. Feedback on the changes points out that the newly created cache.Cache instances are never closed, which leads to background goroutine leaks during testing. It is recommended to register a cleanup function using t.Cleanup to properly close each cache instance.

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.

Comment thread pkg/cache/cache_distributed_test.go Resolved
@kalbasit

kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kalbasit

kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kalbasit

kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kalbasit

kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/cache/cache_distributed_test.go`:
- Around line 196-204: The current test handler (registered via
ts.AddMaybeHandler and referenced by handlerID and narPath) only sleeps before
starting the response, which allows the full 256 KiB body to be sent instantly
once it wakes; change the handler to stream the response body slowly instead of
a single pre-response sleep — e.g., write the body in small chunks with a short
sleep/flush between chunks or use an io.Pipe and delayed writes so readers make
incremental progress; ensure Transfer-Encoding is chunked or omit Content-Length
so chunks are sent progressively, and/or update the assertions (the block around
the former Lines 315-342) to explicitly check that at least one waiter has read
some bytes before the holder finishes to validate the in-flight cross-pod
serving path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e672dff-3218-4f8f-b3b8-5655577ed08e

📥 Commits

Reviewing files that changed from the base of the PR and between 09dc11e and 25ab29a.

📒 Files selected for processing (1)
  • pkg/cache/cache_distributed_test.go

Comment thread pkg/cache/cache_distributed_test.go Resolved
@kalbasit
kalbasit force-pushed the docs-changelog-in-flight-nar branch from 09dc11e to cf1d9bd Compare June 8, 2026 00:11
kalbasit added a commit that referenced this pull request Jun 8, 2026
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from 25ab29a to 78c0fc1 Compare June 8, 2026 00:11
@kalbasit
kalbasit force-pushed the docs-changelog-in-flight-nar branch from b50c288 to dabf4c4 Compare June 8, 2026 01:11
kalbasit added a commit that referenced this pull request Jun 8, 2026
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from 34ea258 to f2b17f2 Compare June 8, 2026 01:11
@kalbasit
kalbasit force-pushed the docs-changelog-in-flight-nar branch from dabf4c4 to 4655157 Compare June 8, 2026 01:19
kalbasit added a commit that referenced this pull request Jun 8, 2026
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from f2b17f2 to 5225aea Compare June 8, 2026 01:19
@kalbasit
kalbasit force-pushed the docs-changelog-in-flight-nar branch from 4655157 to 4108820 Compare June 8, 2026 01:26
kalbasit added a commit that referenced this pull request Jun 8, 2026
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from 5225aea to bb728ce Compare June 8, 2026 01:26
@kalbasit
kalbasit force-pushed the docs-changelog-in-flight-nar branch from 4108820 to 779386f Compare June 8, 2026 01:34
kalbasit added a commit that referenced this pull request Jun 8, 2026
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from bb728ce to 0698e7f Compare June 8, 2026 01:34
Base automatically changed from docs-changelog-in-flight-nar to main June 8, 2026 01:41
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 8, 2026
kalbasit and others added 2 commits June 8, 2026 01:41
End-to-end verification for in-flight NAR staging (group 13). Adds
InflightStagingCrossPodServe to the distributed suite: with staging enabled
(non-CDC, distributed Redis lock, shared store), numInstances replicas
concurrently pull the same large NAR during its download and each must receive
a complete, byte-correct NAR with no truncation. Verified against Redis
(NCPS_ENABLE_REDIS_TESTS=1).

Zero-overhead (feature disabled, and enabled-but-uncontended) is covered
deterministically by the group-5 producer unit tests.
Address review feedback on PR #1361:

- The upstream handler now streams the NAR body in 16 KiB chunks with a pause
  between each, instead of sleeping only before the response starts. A start-only
  delay never put bytes into the holder's temp file during the window, so the
  staging producer had nothing to publish and the cross-pod serve path was not
  actually exercised; trickling the body gives a real in-flight window where parts
  become available progressively and peers tail them (PRRT_kwDONV6tZs6HscSe).
- Each cache instance is now closed via t.Cleanup so the retention-grace reclaim
  goroutines (5-minute grace) are interrupted via shutdownCh rather than leaking
  for the full grace (PRRT_kwDONV6tZs6Hr3GM).

Validated with NCPS_ENABLE_REDIS_TESTS=1: the staging cross-pod subtest passes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the test-cache-cross-pod-in-flight branch from 0698e7f to da1ab82 Compare June 8, 2026 01:41
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 8, 2026
@kalbasit
kalbasit enabled auto-merge (squash) June 8, 2026 01:41
Comment thread pkg/cache/cache_distributed_test.go Dismissed
…race

The in-flight staging producer is spawned via SafeGo capturing the ctx
variable by closure, but pullNarIntoStore reassigns that same variable
shortly after (ctx, span := tracer.Start(...)). The goroutine's read of
ctx in stageInflightNar raced with the parent's write, which the
cross-pod staging race test deterministically catches under -race.

Snapshot ctx into a dedicated stagingCtx before spawning so the
goroutine reads a stable value. The producer is a background op, so the
pre-span ctx is the correct parent anyway.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 8, 2026
@kalbasit
kalbasit merged commit 3ce6e0c into main Jun 8, 2026
70 of 85 checks passed
@kalbasit
kalbasit deleted the test-cache-cross-pod-in-flight branch June 8, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code merge-stack size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants