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.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...)
sum.transferQueueSize += stats.transferQueueSize
sum.oldDuration += stats.oldDuration
sum.oldTimeRanges = append(sum.oldTimeRanges, stats.oldTimeRanges...)
stats.average.mu.Lock()

View file

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