check / check (push) Waiting to run
One progress reporter spans every path of a snapshot. Its counts of files and bytes processed run across all the paths, while the totals they were divided by were reset to each path's own, so a second path smaller than the first showed more than 100% and an ETA of `unknown`. The totals now add up over the paths scanned so far. The rate behind the ETA is measured from the bytes processed since the current path's scan phase ended, so a later path's scan phase does not lower it. SetTotalSize is renamed AddTotalSize because it now adds. The issue says the ETA went negative; it was computed negative and printed as `unknown`. Model: opus-5-5
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
//nolint:testpackage // exercises the unexported processRate helper
|
|
package snapshot
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestProcessRateNotLoweredByLaterScanPhase feeds the reporter two paths
|
|
// that each take 10 seconds to process, the second after a 30-second scan
|
|
// phase. That scan phase processes nothing, so the rate while the second
|
|
// path is processed must be that path's own.
|
|
func TestProcessRateNotLoweredByLaterScanPhase(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const (
|
|
pathSize = 1000
|
|
processingTime = 10 * time.Second
|
|
scanTime = 30 * time.Second
|
|
)
|
|
|
|
// Never started, but Stop releases its tickers and signal handler.
|
|
progress := NewProgressReporter()
|
|
defer progress.Stop()
|
|
|
|
stats := progress.GetStats()
|
|
|
|
// Moves the processing start time back instead of sleeping.
|
|
elapse := func(d time.Duration) {
|
|
stats.mu.Lock()
|
|
defer stats.mu.Unlock()
|
|
|
|
stats.processStartTime = stats.processStartTime.Add(-d)
|
|
}
|
|
|
|
progress.AddTotalSize(pathSize)
|
|
stats.BytesProcessed.Add(pathSize)
|
|
elapse(processingTime)
|
|
|
|
elapse(scanTime)
|
|
progress.AddTotalSize(pathSize)
|
|
stats.BytesProcessed.Add(pathSize)
|
|
elapse(processingTime)
|
|
|
|
want := pathSize / processingTime.Seconds()
|
|
got := stats.processRate()
|
|
|
|
// The test's own run time adds to the elapsed time, so got is a hair
|
|
// under want.
|
|
if got > want || got < want*0.99 {
|
|
t.Errorf("rate while the second path is processed is %.1f bytes/s, "+
|
|
"want %.1f", got, want)
|
|
}
|
|
}
|