Send fetch progress at most once per second (closes #206)
check / check (push) Waiting to run

progressWriter sent an update for every chunk io.Copy wrote, so fetch
logged a line per 32 KiB. It now sends at most one per second, waiting
a second before the first as gen and check do, and one more when the
last byte is written.

TestFetchProgress now checks that a download of several chunks sends no
more than one update per second plus the last.

Model: opus-5-5
This commit is contained in:
2026-10-13 18:26:30 +00:00
parent 24496880c5
commit a826bffca7
2 changed files with 34 additions and 15 deletions
+10 -1
View File
@@ -516,7 +516,7 @@ func TestManifestDownloadStopsAtLimit(t *testing.T) {
func TestFetchProgress(t *testing.T) {
// Create source filesystem with a larger test file
sourceFs := afero.NewMemMapFs()
// Create content large enough to trigger multiple progress updates
// Content large enough that io.Copy writes it in at least four chunks
content := bytes.Repeat([]byte("x"), 100*1024) // 100KB
require.NoError(t, afero.WriteFile(sourceFs, "/large.txt", content, 0o644))
@@ -559,8 +559,11 @@ func TestFetchProgress(t *testing.T) {
}()
// Download
start := time.Now()
err = downloadFile(context.Background(), testClient(),
server.URL+"/large.txt", ".", "large.txt", files[0], progress)
elapsed := time.Since(start)
close(progress)
<-done
@@ -569,6 +572,12 @@ func TestFetchProgress(t *testing.T) {
// Verify we got progress updates
assert.NotEmpty(t, progressUpdates, "should have received progress updates")
// At most one update per second, plus the one reporting the file
// complete: a download that takes under a second sends two at most,
// however many chunks it writes.
assert.LessOrEqual(t, len(progressUpdates), 2+int(elapsed/time.Second),
"one progress update per second at most, plus the last")
// Verify final progress shows complete
if len(progressUpdates) > 0 {
last := progressUpdates[len(progressUpdates)-1]