diff --git a/pkg/testing/fetcher_artifact.go b/pkg/testing/fetcher_artifact.go index d3ec48c249e..51b26cd28c3 100644 --- a/pkg/testing/fetcher_artifact.go +++ b/pkg/testing/fetcher_artifact.go @@ -14,6 +14,7 @@ import ( "path/filepath" "strconv" "strings" + "sync/atomic" "time" ) @@ -256,7 +257,7 @@ func DownloadPackage(ctx context.Context, l Logger, doer httpDoer, downloadPath type writeProgress struct { logger Logger total uint64 - completed uint64 + completed atomic.Uint64 } func newWriteProgress(ctx context.Context, l Logger, total uint64) *writeProgress { @@ -270,7 +271,7 @@ func newWriteProgress(ctx context.Context, l Logger, total uint64) *writeProgres func (wp *writeProgress) Write(p []byte) (int, error) { n := len(p) - wp.completed += uint64(n) + wp.completed.Add(uint64(n)) return n, nil } @@ -282,7 +283,7 @@ func (wp *writeProgress) printProgress(ctx context.Context) { case <-ctx.Done(): return case <-t.C: - wp.logger.Logf("Downloading artifact progress %.2f%%", float64(wp.completed)/float64(wp.total)*100.0) + wp.logger.Logf("Downloading artifact progress %.2f%%", float64(wp.completed.Load())/float64(wp.total)*100.0) } } }