Repository navigation
test: shrink fsck/security/large-narinfo tests - #1242
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughTest-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). ChangesTest Performance Optimization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
|
This change is part of the following stack:
Change managed by git-spice. |
There was a problem hiding this comment.
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.
b3101c9 to
b7413a2
Compare
6df6ab4 to
abf4c46
Compare
f807885 to
ee204a9
Compare
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.
ee204a9 to
f3627df
Compare
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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]>
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):
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):
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):
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):
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):
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:
historical race): already short-mode gated; reducing iterations
would weaken the safety net.
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=1on every touched package;`golangci-lint run` is clean; `nix fmt` shows no changes.