Skip to content

test: shrink fsck/security/large-narinfo tests - #1242

Merged
kalbasit merged 3 commits into
mainfrom
test-shrink-fsck-security-large
May 23, 2026
Merged

kalbasit merged 3 commits into
mainfrom
test-shrink-fsck-security-large

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Continues the previous commit's work. Each remaining outlier had a
concrete cause; this round drops the full suite from ~45.5s to
~41.6s, putting it past the stretch >=50% reduction target vs the
original 88.1s baseline.

pkg/ncps/fsck_test.go TestFsckBackends/SQLite/VerifiedSince
(2.05s -> 0.15s):

  • The "wait long enough that --verified-since 1s actually trips"
    step relied on a 2-second sleep so that the subsequent fsck call
    with --verified-since=1s would not skip. Sub-second timestamp
    precision is available on every supported engine, so swap to a
    100ms sleep and --verified-since=1ms.

pkg/ncps/migrate_narinfo_test.go LargeNarInfo (1.31s -> 0.01s):

  • The "large" narinfo had 100 references, 50 signatures, and a 1 MB
    random NAR body. Migration only walks narinfo files and inserts
    refs/sigs; the NAR body is never read. Shrink references to 20,
    signatures to 10, NAR body to 1 KB; update spot-check indices to
    match. 20 refs is still far above the typical narinfo (2-5).

pkg/server/security_test.go TestSecurity (2.02s -> 0.42s):

  • Four "should NOT reach upstream" subtests each waited a full 500ms
    to confirm the upstream channel stayed empty. An in-process
    httptest.Server roundtrip takes ~1ms, so 100ms is plenty of
    margin. Both arms (positive and negative) now use the same 100ms
    cap.

pkg/cache/cache_internal_test.go (last_accessed_at sleeps):

  • Two more occurrences of "ensure time has moved by one sec" in the
    RunLRU / RunLRUCleanupInconsistentNarInfoState code paths cut from
    1s to 100ms, matching the change already made in cache_test.go in
    the previous commit.

pkg/cache/cache_internal_test.go testConcurrentDecompression
(1.13s -> ~0.3s):

  • The 1 MiB random NAR + zstd compression pre-step dominated wall
    time; the concurrent-decompression assertion is just as strong
    with a 100 KiB payload and saves the bulk of the randomness +
    zstd cost.

Also captures the post-batch profiler output under
openspec/changes/less-tests/after-batch3-timings.txt.

Skipped intentionally:

  • TestCDCChunker_Chunk_ErrorRace (10000 iterations to catch a
    historical race): already short-mode gated; reducing iterations
    would weaken the safety net.
  • TestGetNarInfoDistributedCoordination (1s upstream sleeps): the
    test models inter-instance lock coordination and the 1s/2s
    timeouts give margin against CI load. Risk of flake outweighs the
    ~1s saving.

Verified with go test -race -count=1 on every touched package;
`golangci-lint run` is clean; `nix fmt` shows no changes.

@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: 1efe1a39-5f88-46c8-a42b-981e113d7acf

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6f860 and fbbf68d.

📒 Files selected for processing (1)
  • pkg/ncps/fsck_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Improved test reliability and reduced cost by adjusting timing and sizes: increased sleep windows to account for second‑precision timestamps, shortened waits and timeouts (e.g., to ~100ms/1ms where appropriate), and reduced large test payloads/fixtures (from ~1MiB to ~100KiB and ~1KiB). Comments updated to clarify intent; behavior preserved.

Walkthrough

Test-only changes: increase several cache LRU sleeps to 1100ms, shorten fsck/verified-since windowing and tighten a threshold to 1ms, downsize a migrate-narinfo fixture and NAR payload, and add a 100ms reach timeout constant; several test inputs trimmed (e.g., decompression from 1MiB→100KiB).

Changes

Test Performance Optimization

Layer / File(s) Summary
Cache LRU and decompression test adjustments
pkg/cache/cache_internal_test.go
LRU phase-separating sleeps increased to 1100ms to ensure last_accessed_at advances past MySQL TIMESTAMP second precision. Concurrent decompression test input reduced from 1 MiB to 100 KiB.
Fsck verified-since test timing adjustment
pkg/ncps/fsck_test.go
Post-verification sleep changed to ~1100ms so the next fsck run falls in a different TIMESTAMP second; the --verified-since threshold for the "should NOT skip" case tightened from 1s to 1ms.
Migrate narinfo test fixture downsize
pkg/ncps/migrate_narinfo_test.go
Reduced generated references from 100→20 and signatures from 50→10; replaced large NAR payload with a small placeholder (~1KB); updated spot-check assertions to match new indices.
Security test reach timeout constant
pkg/server/security_test.go
Introduced reachTimeout = 100ms and replaced previous 500ms timeout branches with the constant; comments clarify timing intent and behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • kalbasit/ncps#1241: Also adjusts pkg/cache test timing and decompression payload sizes to align with MySQL timestamp semantics and reduce runtime.

Suggested labels

size:L

"🐰 I hopped through sleeps and bytes,
Trimmed fixtures, shortened waits, and tuned the nights.
Small payloads, steadier time,
CI runs light — a nimble rhyme! 🥕"

🚥 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 directly and clearly summarizes the main change: shrinking test suite performance by reducing several slow tests in fsck, security, and large-narinfo modules.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing specific test optimizations with before/after timings and rationales for each change.
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.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. go Pull requests that update go code labels May 23, 2026

@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 the test suite by reducing sleep durations, data sizes, and iteration counts across several test files. Specifically, it shortens time.Sleep and time.After intervals to 100ms, reduces the size of generated random data for NAR and ZSTD tests, and lowers the number of references and signatures in migration tests. These changes aim to decrease the overall execution time of the tests without compromising their effectiveness. I have no feedback to provide as there were no review comments to evaluate.

@kalbasit
kalbasit force-pushed the test-shrink-go-test-wall-time-48 branch from b3101c9 to b7413a2 Compare May 23, 2026 21:26
@kalbasit
kalbasit force-pushed the test-shrink-fsck-security-large branch from 6df6ab4 to abf4c46 Compare May 23, 2026 21:26
@kalbasit
kalbasit force-pushed the test-shrink-fsck-security-large branch 2 times, most recently from f807885 to ee204a9 Compare May 23, 2026 22:03
Base automatically changed from test-shrink-go-test-wall-time-48 to main May 23, 2026 22:17
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels May 23, 2026
Continues the previous commit's work. Each remaining outlier had a
concrete cause; this round drops the full suite from ~45.5s to
~41.6s, putting it past the stretch >=50% reduction target vs the
original 88.1s baseline.

pkg/ncps/fsck_test.go TestFsckBackends/SQLite/VerifiedSince
(2.05s -> 0.15s):
- The "wait long enough that --verified-since 1s actually trips"
  step relied on a 2-second sleep so that the subsequent fsck call
  with --verified-since=1s would not skip. Sub-second timestamp
  precision is available on every supported engine, so swap to a
  100ms sleep and --verified-since=1ms.

pkg/ncps/migrate_narinfo_test.go LargeNarInfo (1.31s -> 0.01s):
- The "large" narinfo had 100 references, 50 signatures, and a 1 MB
  random NAR body. Migration only walks narinfo files and inserts
  refs/sigs; the NAR body is never read. Shrink references to 20,
  signatures to 10, NAR body to 1 KB; update spot-check indices to
  match. 20 refs is still far above the typical narinfo (2-5).

pkg/server/security_test.go TestSecurity (2.02s -> 0.42s):
- Four "should NOT reach upstream" subtests each waited a full 500ms
  to confirm the upstream channel stayed empty. An in-process
  httptest.Server roundtrip takes ~1ms, so 100ms is plenty of
  margin. Both arms (positive and negative) now use the same 100ms
  cap.

pkg/cache/cache_internal_test.go (last_accessed_at sleeps):
- Two more occurrences of "ensure time has moved by one sec" in the
  RunLRU / RunLRUCleanupInconsistentNarInfoState code paths cut from
  1s to 100ms, matching the change already made in cache_test.go in
  the previous commit.

pkg/cache/cache_internal_test.go testConcurrentDecompression
(1.13s -> ~0.3s):
- The 1 MiB random NAR + zstd compression pre-step dominated wall
  time; the concurrent-decompression assertion is just as strong
  with a 100 KiB payload and saves the bulk of the randomness +
  zstd cost.

Also captures the post-batch profiler output under
openspec/changes/less-tests/after-batch3-timings.txt.

Skipped intentionally:
- TestCDCChunker_Chunk_ErrorRace (10000 iterations to catch a
  historical race): already short-mode gated; reducing iterations
  would weaken the safety net.
- TestGetNarInfoDistributedCoordination (1s upstream sleeps): the
  test models inter-instance lock coordination and the 1s/2s
  timeouts give margin against CI load. Risk of flake outweighs the
  ~1s saving.

Verified with `go test -race -count=1` on every touched package;
\`golangci-lint run\` is clean; \`nix fmt\` shows no changes.
@kalbasit
kalbasit force-pushed the test-shrink-fsck-security-large branch from ee204a9 to f3627df Compare May 23, 2026 22:17
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 23, 2026
@kalbasit
kalbasit enabled auto-merge (squash) May 23, 2026 22:17
MySQL TIMESTAMP has second-level precision. The LRU cleanup test
uses two access phases separated by a sleep to ensure phase-2
entries have a newer last_accessed_at than phase-1-only entries,
so the LRU correctly evicts the latter and preserves the former.

With only 100ms between phases, MySQL truncates both timestamps to
the same second, the LRU cannot distinguish recency, and it may
evict a phase-2 entry that should survive — causing the "not found"
assertion at cache_internal_test.go:834.

Fix both occurrences by increasing the sleep to 1100ms (>1 full
second) to guarantee the timestamps differ under MySQL.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@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 (112bebb) to head (fbbf68d).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1242   +/-   ##
=====================================
  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.

MySQL TIMESTAMP has second-level precision. The 100ms sleep between
fsck step 1 (which sets verifiedAt1) and step 3 (which must produce
a different verified_at) was not enough: both timestamps landed on
the same second, causing the NotEqual assertion to fail.

Increase the sleep to 1100ms so step 3's fsck write is guaranteed
to land in a different MySQL second than step 1's.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kalbasit
kalbasit merged commit 2362605 into main May 23, 2026
21 checks passed
@kalbasit
kalbasit deleted the test-shrink-fsck-security-large branch May 23, 2026 22:58
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