Skip to content

test: shrink integration outliers (s3 bucket, redis TTL, NAR) - #1244

Merged
kalbasit merged 1 commit into
mainfrom
test-shrink-integration-outliers
May 23, 2026
Merged

kalbasit merged 1 commit into
mainfrom
test-shrink-integration-outliers

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Continuation of the integration-test wall-time work. Builds on the
fix(ncps): close dbClient on shutdown commit, which already removed
~16s of DROP DATABASE wait. This commit picks off the remaining
named integration outliers:

pkg/storage/s3 TestNew_BucketAccessError (5.22s -> ~0s):

  • The RoundTripper mock returned a Go error, triggering minio-go's
    exponential-backoff retry loop (~5s before giving up). Replace
    with s3ErrorResponse() so the SDK gives up immediately on the
    non-retryable 403. The production wrapper at s3.go:95 already
    wraps any non-nil err with "error testing bucket access", so the
    Contains() assertion still passes. The now-unused
    errTestingBucketAccess sentinel is removed.

pkg/cache TestDistributedBackends/.../LockFailover (4.51s -> ~1s
each, x3 backends):

  • shortTTL: 2s -> 500ms (sleep matched at 800ms).
  • ctx2 timeout: 500ms -> 200ms — still well under shortTTL so the
    "second locker fails while first holds the lock" check is sound.
  • Total saving across the three backend variants: ~10s of test
    wall time.

pkg/cache TestDistributedBackends/.../LargeNARConcurrentDownload
(5.4s -> ~1s each, x3 backends):

  • NAR payload 2 MiB -> 256 KiB. The test exercises concurrent
    download coordination, not raw throughput; 256 KiB still trips
    CDC chunking and keeps the lock dance honest.
  • Server-side artificial delay 2s -> 300ms. The only requirement is
    that follower goroutines arrive while the first download is in
    flight, and goroutine scheduling latency is sub-millisecond on a
    quiet machine.

pkg/lock/redis TestLocker_LockExpiry (2.01s -> ~0.6s):

  • Lock TTL 1s -> 200ms, post-expiry sleep 2s -> 400ms. Redis lock
    expiry is millisecond-granular; 400ms is plenty of safety.

pkg/lock/redis TestLocker_DegradedModeDisabled (1.72s -> ~0.5s):

  • The "unreachable Redis port" call previously waited on the
    go-redis default DialTimeout (5s) per attempt. Wrap ctx in a
    500ms WithTimeout so the failure surfaces fast — matches the
    same fix already applied to TestNewLocker_ReturnType.

Skipped intentionally:

  • TestDistributedBackends/.../PutNarInfoConcurrentSharedNar (50
    iterations to catch a concurrency race) — same policy as the
    chunker race test; reducing iterations weakens the safety net.

Cumulative integration-test wall time (full suite, all deps live):
~64.40s -> ~58.99s after this commit. Combined with the previous
dbClient fix, integration baseline 80.09s -> 58.99s (~26% lower).

Captures the post-batch profile under
openspec/changes/less-tests/integration-after-batch5-timings.txt.

Verified: `go test -race` on every touched package passes;
`golangci-lint run` is clean.

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

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4b79b1a-906e-48d2-ac23-92e88cbfb70d

📥 Commits

Reviewing files that changed from the base of the PR and between 684c5a5 and 27b0281.

📒 Files selected for processing (3)
  • pkg/cache/cache_distributed_test.go
  • pkg/lock/redis/redis_test.go
  • pkg/storage/s3/s3_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Optimized test suite to run faster by reducing timing windows for locks and wait periods.
    • Shrunk large mocked payloads and shortened artificial server delays to cut runtime.
    • Improved failure simulations for storage and lock scenarios to make tests more deterministic and millisecond-granular.

Walkthrough

Tests updated: distributed cache and Redis lock tests use shorter TTLs/wait bounds and a bounded context; concurrent NAR test reduces payload and server delay; S3 bucket-access test now returns a 403 HTTP mock response instead of a RoundTripper error.

Changes

Test Timing and Mock Optimization

Layer / File(s) Summary
Distributed cache failover and concurrent download timing
pkg/cache/cache_distributed_test.go
Lock TTL reduced to 500ms; second locker acquire attempt bounded to 200ms; large NAR size reduced to 256KiB; server GET artificial delay reduced to 300ms.
Redis lock expiry and degraded-mode timeout
pkg/lock/redis/redis_test.go
Lock expiry test uses 200ms TTL and 400ms wait; degraded-mode test uses a context.WithTimeout of 500ms with deferred cancel to avoid long dial timeouts.
S3 bucket access mock response change
pkg/storage/s3/s3_test.go
Removed the extra error sentinel; TestNew_BucketAccessError now returns a non-retryable 403 S3-style HTTP response from the mock transport instead of returning a RoundTripper error.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

Suggested labels

size:L

Poem

🐇 I tighten timers, trim the load,

Tests hop faster down the road.
Mocked replies keep errors true,
Shorter waits — a quicker queue.
Hooray, the rabbit says — tests pass anew!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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: shrink integration outliers (s3 bucket, redis TTL, NAR)' directly and specifically summarizes the main change: reducing integration test execution time by optimizing specific test cases in three modules.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing each test optimization with before/after timings, rationale, and verification steps across all modified files.
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

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 optimizes test execution speed by reducing TTLs, sleep durations, and timeouts across distributed cache, Redis locking, and S3 storage tests. Notable changes include decreasing the NAR size for concurrent download scenarios and returning non-retryable 403 errors in S3 mocks to avoid SDK retry delays. Feedback suggests that the 200ms timeout for lock contention checks might be too tight for high-load environments, potentially leading to flaky tests, and recommends using TryLock for more deterministic verification.

Comment thread pkg/cache/cache_distributed_test.go Resolved
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from 411ed9e to 743ec78 Compare May 23, 2026 21:26
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from dba7e1e to 2e2fcbe Compare May 23, 2026 21:26
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from 743ec78 to 0d81c5c Compare May 23, 2026 21:51
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from 2e2fcbe to 2530d08 Compare May 23, 2026 21:51
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from 0d81c5c to 6aacbc7 Compare May 23, 2026 22:03
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from 2530d08 to babdf33 Compare May 23, 2026 22:03
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from 6aacbc7 to e6e746b Compare May 23, 2026 22:17
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from babdf33 to f3d9b91 Compare May 23, 2026 22:17
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from e6e746b to d0524aa Compare May 23, 2026 22:28
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from f3d9b91 to f54c8bb Compare May 23, 2026 22:28
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from d0524aa to 4a6c1a2 Compare May 23, 2026 22:45
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from f54c8bb to 5f830c5 Compare May 23, 2026 22:45
@kalbasit
kalbasit force-pushed the fix-ncps-close-dbclient-on branch from 4a6c1a2 to a13d438 Compare May 23, 2026 22:58
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from 5f830c5 to 684c5a5 Compare May 23, 2026 22:58
Base automatically changed from fix-ncps-close-dbclient-on to main May 23, 2026 23:11
@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 May 23, 2026
Continuation of the integration-test wall-time work. Builds on the
fix(ncps): close dbClient on shutdown commit, which already removed
~16s of DROP DATABASE wait. This commit picks off the remaining
named integration outliers:

pkg/storage/s3 TestNew_BucketAccessError (5.22s -> ~0s):
- The RoundTripper mock returned a Go error, triggering minio-go's
  exponential-backoff retry loop (~5s before giving up). Replace
  with s3ErrorResponse() so the SDK gives up immediately on the
  non-retryable 403. The production wrapper at s3.go:95 already
  wraps any non-nil err with "error testing bucket access", so the
  Contains() assertion still passes. The now-unused
  errTestingBucketAccess sentinel is removed.

pkg/cache TestDistributedBackends/.../LockFailover (4.51s -> ~1s
each, x3 backends):
- shortTTL: 2s -> 500ms (sleep matched at 800ms).
- ctx2 timeout: 500ms -> 200ms — still well under shortTTL so the
  "second locker fails while first holds the lock" check is sound.
- Total saving across the three backend variants: ~10s of test
  wall time.

pkg/cache TestDistributedBackends/.../LargeNARConcurrentDownload
(5.4s -> ~1s each, x3 backends):
- NAR payload 2 MiB -> 256 KiB. The test exercises concurrent
  download coordination, not raw throughput; 256 KiB still trips
  CDC chunking and keeps the lock dance honest.
- Server-side artificial delay 2s -> 300ms. The only requirement is
  that follower goroutines arrive while the first download is in
  flight, and goroutine scheduling latency is sub-millisecond on a
  quiet machine.

pkg/lock/redis TestLocker_LockExpiry (2.01s -> ~0.6s):
- Lock TTL 1s -> 200ms, post-expiry sleep 2s -> 400ms. Redis lock
  expiry is millisecond-granular; 400ms is plenty of safety.

pkg/lock/redis TestLocker_DegradedModeDisabled (1.72s -> ~0.5s):
- The "unreachable Redis port" call previously waited on the
  go-redis default DialTimeout (5s) per attempt. Wrap ctx in a
  500ms WithTimeout so the failure surfaces fast — matches the
  same fix already applied to TestNewLocker_ReturnType.

Skipped intentionally:
- TestDistributedBackends/.../PutNarInfoConcurrentSharedNar (50
  iterations to catch a concurrency race) — same policy as the
  chunker race test; reducing iterations weakens the safety net.

Cumulative integration-test wall time (full suite, all deps live):
~64.40s -> ~58.99s after this commit. Combined with the previous
dbClient fix, integration baseline 80.09s -> 58.99s (~26% lower).

Captures the post-batch profile under
openspec/changes/less-tests/integration-after-batch5-timings.txt.

Verified: \`go test -race\` on every touched package passes;
\`golangci-lint run\` is clean.
@kalbasit
kalbasit force-pushed the test-shrink-integration-outliers branch from 684c5a5 to 27b0281 Compare May 23, 2026 23:11
@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 May 23, 2026
@kalbasit
kalbasit enabled auto-merge (squash) May 23, 2026 23:11
@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.50%. Comparing base (d73a8a2) to head (27b0281).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1244   +/-   ##
=====================================
  Coverage   5.50%   5.50%           
=====================================
  Files          6       6           
  Lines        400     400           
=====================================
  Hits          22      22           
  Misses       374     374           
  Partials       4       4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit merged commit 9e8529e into main May 23, 2026
23 checks passed
@kalbasit
kalbasit deleted the test-shrink-integration-outliers branch May 23, 2026 23:24
kalbasit added a commit that referenced this pull request May 24, 2026
dev-scripts/test-migration-e2e.py (PR #1233):
- PRRT_kwDONV6tZs6EU7OZ: raise in stop_ncps if port never
  closes (was silently ignored).
- PRRT_kwDONV6tZs6EU7Ob: raise on unparseable idempotency
  output instead of downgrading to a WARN log.
- PRRT_kwDONV6tZs6EVEfJ: wait_ready() takes the process
  handle and exits early when ncps dies before becoming
  ready, avoiding the full 120s timeout.

dev-scripts/run.py (PR #1232):
- PRRT_kwDONV6tZs6EU663: guard dbmate create with
  shutil.which(), matching the existing pattern for
  perform_clean(); raises FileNotFoundError with a clear
  message instead of a confusing FileNotFoundError from
  subprocess.

pkg/cache/cdc_test.go (PR #1241):
- PRRT_kwDONV6tZs6EVhVS: increase chunkingDelay 500ms→1s
  to reduce flakiness under -race on loaded CI.

pkg/cache/cache_distributed_test.go (PR #1244):
- PRRT_kwDONV6tZs6EVZVc: replace Lock+200ms timeout with
  TryLock (non-blocking) for lock-contention check;
  deterministic and immune to slow Redis round-trips.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant