diff --git a/fs/accounting/stats_groups.go b/fs/accounting/stats_groups.go index 6bcd1ea20..776af484c 100644 --- a/fs/accounting/stats_groups.go +++ b/fs/accounting/stats_groups.go @@ -366,6 +366,8 @@ func (sg *statsGroups) sum() *StatsInfo { sum.lastError = stats.lastError } sum.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...) + sum.oldDuration += stats.oldDuration + sum.oldTimeRanges = append(sum.oldTimeRanges, stats.oldTimeRanges...) } stats.mu.RUnlock() } diff --git a/fs/accounting/stats_groups_test.go b/fs/accounting/stats_groups_test.go index 76d93bf64..224dff9ef 100644 --- a/fs/accounting/stats_groups_test.go +++ b/fs/accounting/stats_groups_test.go @@ -4,8 +4,10 @@ import ( "fmt" "runtime" "testing" + "time" "github.com/rclone/rclone/fstest/testy" + "github.com/stretchr/testify/assert" ) func TestStatsGroupOperations(t *testing.T) { @@ -43,17 +45,26 @@ func TestStatsGroupOperations(t *testing.T) { t.Parallel() stats1 := NewStats() stats1.bytes = 5 - stats1.errors = 5 + stats1.errors = 6 + stats1.oldDuration = time.Second + stats1.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(time.Second)}} stats2 := NewStats() + stats2.bytes = 10 + stats2.errors = 12 + stats2.oldDuration = 2 * time.Second + stats2.oldTimeRanges = []timeRange{{time.Now(), time.Now().Add(2 * time.Second)}} sg := newStatsGroups() sg.set("test1", stats1) sg.set("test2", stats2) sum := sg.sum() - if sum.bytes != stats1.bytes+stats2.bytes { - t.Fatalf("sum() => bytes %d, expected %d", sum.bytes, stats1.bytes+stats2.bytes) - } - if sum.errors != stats1.errors+stats2.errors { - t.Fatalf("sum() => errors %d, expected %d", sum.errors, stats1.errors+stats2.errors) + assert.Equal(t, stats1.bytes+stats2.bytes, sum.bytes) + assert.Equal(t, stats1.errors+stats2.errors, sum.errors) + assert.Equal(t, stats1.oldDuration+stats2.oldDuration, sum.oldDuration) + // dict can iterate in either order + a := timeRanges{stats1.oldTimeRanges[0], stats2.oldTimeRanges[0]} + b := timeRanges{stats2.oldTimeRanges[0], stats1.oldTimeRanges[0]} + if !assert.ObjectsAreEqual(a, sum.oldTimeRanges) { + assert.Equal(t, b, sum.oldTimeRanges) } })