accounting: stop averaging when the last check finishes
Release the averaging goroutine when checks outlast transfers, with a regression
test for the completion order.
Assisted-by: OpenAI Codex
(cherry picked from commit 4f0148db0c)
This commit is contained in:
1 parent
277d3ea146
commit
70700de356
2 files changed
+26
No files matched your search
@@ -803,6 +803,9 @@ func (s *StatsInfo) DoneChecking(remote string) {
|
||||
s.checking.del(remote)
|
||||
s.mu.Lock()
|
||||
s.checks++
|
||||
if s.transferring.empty() && s.checking.empty() {
|
||||
s._stopAverageLoop()
|
||||
}
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,33 @@ import (
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/fserrors"
|
||||
"github.com/rclone/rclone/fstest/mockobject"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAverageLoopStopsAfterLastCheck(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
stats := NewStats(ctx)
|
||||
t.Cleanup(func() {
|
||||
stats.mu.Lock()
|
||||
defer stats.mu.Unlock()
|
||||
stats._stopAverageLoop()
|
||||
})
|
||||
transfer := stats.NewTransferRemoteSize("transfer", 0, nil, nil)
|
||||
firstCheck := stats.NewCheckingTransfer(mockobject.New("first"), "checking")
|
||||
lastCheck := stats.NewCheckingTransfer(mockobject.New("last"), "checking")
|
||||
|
||||
transfer.Done(ctx, nil)
|
||||
firstCheck.Done(ctx, nil)
|
||||
assert.True(t, stats.average.started, "a check is still active")
|
||||
|
||||
lastCheck.Done(ctx, nil)
|
||||
assert.False(t, stats.average.started, "completed checks must release the averaging goroutine")
|
||||
assert.Equal(t, int64(2), stats.GetChecks())
|
||||
assert.Equal(t, int64(1), stats.GetTransfers())
|
||||
}
|
||||
|
||||
func TestETA(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
size, total int64
|
||||
|
||||
Reference in new issue
Block a user