mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 01:20:27 +00:00
Fix tests: use StartTestCustomServer (no Content-Length) to match real bug scenario
Remove StartTestNoRangeServer and its tests since the real bug is about servers that don't return Content-Length at all (like GitHub's zip downloads), not servers with Content-Length but no Range support. The chunked tests (TestFetcher_DownloadChunkedContinue and TestFetcher_DownloadChunkedNotExceedSize) correctly simulate the real-world bug using StartTestCustomServer which serves files without Content-Length. Co-authored-by: monkeyWie <[email protected]>
This commit is contained in:
1 parent
b8e517b35b
commit
8b02844ec3
2 files changed
+4
-74
No files matched your search
@@ -314,62 +314,11 @@ func TestFetcher_DownloadChunkedContinue(t *testing.T) {
|
||||
downloadContinue(listener, 1, t)
|
||||
}
|
||||
|
||||
func TestFetcher_DownloadNoRangeWithSize(t *testing.T) {
|
||||
listener := test.StartTestNoRangeServer()
|
||||
defer listener.Close()
|
||||
|
||||
downloadNormal(listener, 1, t)
|
||||
}
|
||||
|
||||
func TestFetcher_DownloadNoRangeContinue(t *testing.T) {
|
||||
listener := test.StartTestNoRangeServer()
|
||||
defer listener.Close()
|
||||
|
||||
downloadContinue(listener, 1, t)
|
||||
}
|
||||
|
||||
// TestFetcher_DownloadNoRangeNotExceedSize verifies that when a server returns
|
||||
// Content-Length but doesn't support Range requests, the downloaded bytes never
|
||||
// exceed the total file size after pause and resume.
|
||||
func TestFetcher_DownloadNoRangeNotExceedSize(t *testing.T) {
|
||||
listener := test.StartTestNoRangeServer()
|
||||
defer listener.Close()
|
||||
|
||||
fetcher := downloadReady(listener, 1, t)
|
||||
err := fetcher.Start()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Let it download some data
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
if err := fetcher.Pause(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
if err := fetcher.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = fetcher.Wait()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Verify total downloaded does not exceed file size
|
||||
totalDownloaded := fetcher.Progress().TotalDownloaded()
|
||||
if totalDownloaded > test.BuildSize {
|
||||
t.Errorf("Downloaded %d bytes exceeds file size %d", totalDownloaded, test.BuildSize)
|
||||
}
|
||||
|
||||
want := test.FileMd5(test.BuildFile)
|
||||
got := test.FileMd5(test.DownloadFile)
|
||||
if want != got {
|
||||
t.Errorf("Download() got = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestFetcher_DownloadChunkedNotExceedSize verifies that when a server doesn't
|
||||
// return Content-Length (chunked transfer), the download properly handles
|
||||
// pause/resume without accumulating extra bytes.
|
||||
// return Content-Length (chunked transfer, no Range support), the download
|
||||
// properly handles pause/resume without accumulating extra bytes.
|
||||
// This simulates the real-world bug where servers like GitHub's zip downloads
|
||||
// don't return Content-Length.
|
||||
func TestFetcher_DownloadChunkedNotExceedSize(t *testing.T) {
|
||||
listener := test.StartTestCustomServer()
|
||||
defer listener.Close()
|
||||
|
||||
Reference in new issue
Block a user