1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-06 02:23:24 +00:00

accounting: add context.Context #3257 #4685

This commit is contained in:
Nick Craig-Wood
2020-11-05 16:59:59 +00:00
parent e3fe31f7cb
commit 1fb6ad700f
29 changed files with 138 additions and 109 deletions

View File

@@ -1,6 +1,7 @@
package accounting
import (
"context"
"fmt"
"io"
"testing"
@@ -67,7 +68,8 @@ func TestPercentage(t *testing.T) {
}
func TestStatsError(t *testing.T) {
s := NewStats()
ctx := context.Background()
s := NewStats(ctx)
assert.Equal(t, int64(0), s.GetErrors())
assert.False(t, s.HadFatalError())
assert.False(t, s.HadRetryError())
@@ -132,6 +134,7 @@ func TestStatsError(t *testing.T) {
}
func TestStatsTotalDuration(t *testing.T) {
ctx := context.Background()
startTime := time.Now()
time1 := startTime.Add(-40 * time.Second)
time2 := time1.Add(10 * time.Second)
@@ -139,7 +142,7 @@ func TestStatsTotalDuration(t *testing.T) {
time4 := time3.Add(10 * time.Second)
t.Run("Single completed transfer", func(t *testing.T) {
s := NewStats()
s := NewStats(ctx)
tr1 := &Transfer{
startedAt: time1,
completedAt: time2,
@@ -158,7 +161,7 @@ func TestStatsTotalDuration(t *testing.T) {
})
t.Run("Single uncompleted transfer", func(t *testing.T) {
s := NewStats()
s := NewStats(ctx)
tr1 := &Transfer{
startedAt: time1,
}
@@ -174,7 +177,7 @@ func TestStatsTotalDuration(t *testing.T) {
})
t.Run("Overlapping without ending", func(t *testing.T) {
s := NewStats()
s := NewStats(ctx)
tr1 := &Transfer{
startedAt: time2,
completedAt: time3,
@@ -218,7 +221,7 @@ func TestStatsTotalDuration(t *testing.T) {
})
t.Run("Mixed completed and uncompleted transfers", func(t *testing.T) {
s := NewStats()
s := NewStats(ctx)
s.AddTransfer(&Transfer{
startedAt: time1,
completedAt: time2,
@@ -382,6 +385,7 @@ func TestTimeRangeDuration(t *testing.T) {
}
func TestPruneTransfers(t *testing.T) {
ctx := context.Background()
for _, test := range []struct {
Name string
Transfers int
@@ -406,7 +410,7 @@ func TestPruneTransfers(t *testing.T) {
MaxCompletedTransfers = test.Limit
defer func() { MaxCompletedTransfers = prevLimit }()
s := NewStats()
s := NewStats(ctx)
for i := int64(1); i <= int64(test.Transfers); i++ {
s.AddTransfer(&Transfer{
startedAt: time.Unix(i, 0),