test(download): add integration tests with HTTP test server #161
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/pget!161
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/integration-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add comprehensive integration tests (16 tests) using httptest.NewServer. Also fix two real bugs discovered during testing.
Why
No test coverage existed for the core download engine. Tests caught a data race and a concurrent write corruption bug.
Tests
Bugs Fixed
writeAtSeeker embedded
*os.File—io.CopyNcalledos.File.ReadFrom(sendfile) which wrote at the shared file offset instead of viaWriteAt, corrupting concurrent chunk writes. Fixed by storing*os.Fileas a named field instead of embedding.progress.Tracker data race — Multiple workers called
bar.Set()concurrently while the render goroutine readbar.String(). Fixed by adding async.Mutexaround bar access.Testing
go test -race ./...— all pass, no racesgo build ./...,go vet ./...,golangci-lint run— all cleanBreaking Changes
None — both bugs were latent and produced wrong output under concurrent downloads.
Closes #112, #108, #109, #110, #111
c2d65d602556f57056e9Review: APPROVED
Verification
go test -race ./internal/downloader/...— ✅ 4.3s, all passgo test -race ./internal/progress/...— ✅ 1.0s, all passgo vet ./...— ✅ passesChanges
internal/downloader/download_test.go(new, 534 lines) — 16 integration tests usinghttptest.NewServerinternal/downloader/download.go—writeAtSeekerno longer embeds*os.File(named fieldfile+ explicitWriteAt), fixing concurrent chunk corruptioninternal/progress/progress.go—sync.Mutexaroundbar.Set()/bar.String()calls, fixing data raceBugs fixed
io.CopyNcalledos.File.ReadFrom(sendfile) via promoted method, bypassingWriteAt. Fixed by storing*os.Fileas named field.bar.Set()from workers +bar.String()from render goroutine. Fixed withsync.Mutex.Test coverage (16 tests)
SplitChunks, BuildRangeHeader, ProbeURL (range + no-range + Content-Disposition), Download (parallel + single-stream + resume + checksum + retry + retry-exhausted + rate-limit + context-cancel), UniquePath, HumanBytes, ParseFTPURL, IsFTPURL, VerifyChecksum
Closes #108, #109, #110, #111, #112 on merge.