🧱 Chunk is a download manager for slow and unstable servers
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #47 from cuducos/fix-report-already-downloaded-bytes

Reports already downloaded bytes as downloaded

authored by

Eduardo Cuducos and committed by
GitHub
e62f47af 9bb80b84

+35
+2
downloader.go
··· 289 289 return 290 290 } 291 291 if !pending { 292 + s.DownloadedFileBytes = atomic.AddInt64(&downloadedBytes, c.size()) 293 + ch <- s 292 294 continue 293 295 } 294 296 urlDownload.Add(1)
+33
downloader_test.go
··· 235 235 } 236 236 } 237 237 238 + func TestDownload_ReportPreviouslyDownloadedBytes(t *testing.T) { 239 + tmp := t.TempDir() 240 + firstChunk := func(url string) DownloadStatus { 241 + d := Downloader{ 242 + OutputDir: tmp, 243 + MaxRetries: 1, 244 + ConcurrencyPerServer: 1, 245 + ChunkSize: 3, 246 + } 247 + ch := d.Download(url) 248 + <-ch // discard the first status (just the file size) 249 + return <-ch 250 + } 251 + 252 + // first download attempt (with server up) 253 + url, first := func() (string, DownloadStatus) { 254 + s := httptest.NewServer(http.HandlerFunc( 255 + func(w http.ResponseWriter, r *http.Request) { 256 + fmt.Fprint(w, "42") 257 + }, 258 + )) 259 + defer s.Close() 260 + got := firstChunk(s.URL) 261 + return s.URL, got 262 + }() 263 + 264 + // second download attempt (with server down) 265 + second := firstChunk(url) 266 + if first.DownloadedFileBytes != second.DownloadedFileBytes { 267 + t.Errorf("expected the same number of downloaded bytes, got %d and %d", first.DownloadedFileBytes, second.DownloadedFileBytes) 268 + } 269 + } 270 + 238 271 func TestDownloadWithContext_ErrorUserTimeout(t *testing.T) { 239 272 userTimeout := 250 * time.Millisecond // please note that the user timeout is less than the timeout per chunk. 240 273 timeout := 10 * userTimeout