fs: Fix transferTime not being set in JSON logs

This was unintentionally broken in 04aa696
This commit is contained in:
Jacob Hands 2023-08-16 16:12:35 -05:00 committed by Nick Craig-Wood
parent ea4aa696a5
commit cf5457c2cd
2 changed files with 24 additions and 0 deletions

View File

@ -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
}

View File

@ -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))