mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
33 lines
657 B
Go
33 lines
657 B
Go
package stats
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTimingStats(t *testing.T) {
|
|
t.Parallel()
|
|
start := time.Now()
|
|
now = func() time.Time {
|
|
return start
|
|
}
|
|
defer func() {
|
|
now = time.Now
|
|
}()
|
|
ts := NewTimingStats()
|
|
now = func() time.Time {
|
|
return start.Add(100 * time.Millisecond)
|
|
}
|
|
ts.AddCheckpoint("checkpoint-1")
|
|
now = func() time.Time {
|
|
return start.Add(300 * time.Millisecond)
|
|
}
|
|
ts.AddCheckpoint("checkpoint-2")
|
|
timings := ts.Timings()
|
|
assert.Len(t, timings, 2)
|
|
assert.Equal(t, 100*time.Millisecond, timings["checkpoint-1"])
|
|
assert.Equal(t, 200*time.Millisecond, timings["checkpoint-2"])
|
|
}
|