1
mirror of https://github.com/rclone/rclone synced 2024-11-17 17:30:37 +01:00

stats: fix missing computation of transferQueueSize when summing up statistics group - fixes #5749

This commit is contained in:
Carlo Mion 2021-10-24 17:58:39 +02:00 committed by Nick Craig-Wood
parent 7bd853ce35
commit c2600f9e4d
2 changed files with 4 additions and 0 deletions

View File

@ -373,6 +373,7 @@ func (sg *statsGroups) sum(ctx context.Context) *StatsInfo {
sum.lastError = stats.lastError sum.lastError = stats.lastError
} }
sum.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...) sum.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...)
sum.transferQueueSize += stats.transferQueueSize
sum.oldDuration += stats.oldDuration sum.oldDuration += stats.oldDuration
sum.oldTimeRanges = append(sum.oldTimeRanges, stats.oldTimeRanges...) sum.oldTimeRanges = append(sum.oldTimeRanges, stats.oldTimeRanges...)
stats.average.mu.Lock() stats.average.mu.Lock()

View File

@ -47,12 +47,14 @@ func TestStatsGroupOperations(t *testing.T) {
t.Parallel() t.Parallel()
stats1 := NewStats(ctx) stats1 := NewStats(ctx)
stats1.bytes = 5 stats1.bytes = 5
stats1.transferQueueSize = 10
stats1.errors = 6 stats1.errors = 6
stats1.oldDuration = time.Second stats1.oldDuration = time.Second
stats1.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(time.Second)}} stats1.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(time.Second)}}
stats2 := NewStats(ctx) stats2 := NewStats(ctx)
stats2.bytes = 10 stats2.bytes = 10
stats2.errors = 12 stats2.errors = 12
stats1.transferQueueSize = 20
stats2.oldDuration = 2 * time.Second stats2.oldDuration = 2 * time.Second
stats2.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(2 * time.Second)}} stats2.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(2 * time.Second)}}
sg := newStatsGroups() sg := newStatsGroups()
@ -60,6 +62,7 @@ func TestStatsGroupOperations(t *testing.T) {
sg.set(ctx, "test2", stats2) sg.set(ctx, "test2", stats2)
sum := sg.sum(ctx) sum := sg.sum(ctx)
assert.Equal(t, stats1.bytes+stats2.bytes, sum.bytes) assert.Equal(t, stats1.bytes+stats2.bytes, sum.bytes)
assert.Equal(t, stats1.transferQueueSize+stats2.transferQueueSize, sum.transferQueueSize)
assert.Equal(t, stats1.errors+stats2.errors, sum.errors) assert.Equal(t, stats1.errors+stats2.errors, sum.errors)
assert.Equal(t, stats1.oldDuration+stats2.oldDuration, sum.oldDuration) assert.Equal(t, stats1.oldDuration+stats2.oldDuration, sum.oldDuration)
assert.Equal(t, stats1.average.speed+stats2.average.speed, sum.average.speed) assert.Equal(t, stats1.average.speed+stats2.average.speed, sum.average.speed)