perf: reduce CI test time from ~97s to ~5s#9
Merged
Conversation
The download package tests were the CI bottleneck, consuming ~92s of the ~97s unit test step. Three root causes: 1. TestDownloadFileTimeout had a 60s server-side sleep. The client context timed out in 1s, but httptest.Server.Close() blocked waiting for the handler goroutine. Fixed by making the handler respect the request context so it exits immediately on cancellation. 2. TestDownloadFileContextCancellation sent 100 chunks with 100ms sleeps (10s total). Reduced to 50 chunks at 10ms with context-aware select loops. 3. Multiple retry tests (ServerError, ChecksumMismatch, SizeValidation, Retry) used real exponential backoff sleeps (1-3s each). Made the backoff function injectable on Client via a BackoffFunc field, with test helper that sets zero-delay backoff. Also reduced TestPoolContextCancellation and TestPoolConcurrency server delays proportionally. All 13 packages still pass. No production code behavior changes — the BackoffFunc field defaults to the existing calculateBackoffDelay. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
internal/downloadpackage tests took ~92 seconds (of ~97s total test step), making it the sole CI bottleneckClientvia aBackoffFuncfield so tests use zero-delay backoff instead of real exponential sleeps (1-3s per retry)httptest.Server.Close()returns immediately instead of blocking on in-flight handler goroutinestime.Sleepdurations in concurrency and cancellation testsBefore → After (download package)
No production code behavior changes —
BackoffFuncdefaults to the existingcalculateBackoffDelay.Test plan
go test -count=1 ./...)go vet ./...clean🤖 Generated with Claude Code