From cf5457c2cd033f2774d716b34d85b1cbf28272a6 Mon Sep 17 00:00:00 2001 From: Jacob Hands Date: Wed, 16 Aug 2023 16:12:35 -0500 Subject: [PATCH] fs: Fix transferTime not being set in JSON logs This was unintentionally broken in 04aa696 --- fs/accounting/stats.go | 2 ++ fs/accounting/stats_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go index 0faa74180..24c9bcda1 100644 --- a/fs/accounting/stats.go +++ b/fs/accounting/stats.go @@ -313,6 +313,8 @@ func (s *StatsInfo) calculateTransferStats() (ts transferStats) { // we take it off here to avoid double counting ts.totalBytes = s.transferQueueSize + s.bytes + transferringBytesTotal - transferringBytesDone ts.speed = s.average.speed + dt := s.totalDuration() + ts.transferTime = dt.Seconds() return ts } diff --git a/fs/accounting/stats_test.go b/fs/accounting/stats_test.go index 58e8150bd..773311824 100644 --- a/fs/accounting/stats_test.go +++ b/fs/accounting/stats_test.go @@ -251,6 +251,28 @@ func TestStatsTotalDuration(t *testing.T) { }) } +func TestRemoteStats(t *testing.T) { + ctx := context.Background() + startTime := time.Now() + time1 := startTime.Add(-40 * time.Second) + time2 := time1.Add(10 * time.Second) + + t.Run("Single completed transfer", func(t *testing.T) { + s := NewStats(ctx) + tr1 := &Transfer{ + startedAt: time1, + completedAt: time2, + } + s.AddTransfer(tr1) + time.Sleep(time.Millisecond) + rs, err := s.RemoteStats() + + require.NoError(t, err) + assert.Equal(t, float64(10), rs["transferTime"]) + assert.Greater(t, rs["elapsedTime"], float64(0)) + }) +} + // make time ranges from string description for testing func makeTimeRanges(t *testing.T, in []string) timeRanges { trs := make(timeRanges, len(in))