Skip to content

Commit

Permalink
metrics: make flawed test less flawed (ethereum#20818)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 10, 2024
1 parent 5f64a36 commit 161336d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions metrics/timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,23 @@ func TestTimerStop(t *testing.T) {
}

func TestTimerFunc(t *testing.T) {
tm := NewTimer()
tm.Time(func() { time.Sleep(50e6) })
if max := tm.Max(); 35e6 > max || max > 95e6 {
t.Errorf("tm.Max(): 35e6 > %v || %v > 95e6\n", max, max)
var (
tm = NewTimer()
testStart = time.Now()
actualTime time.Duration
)
tm.Time(func() {
time.Sleep(50 * time.Millisecond)
actualTime = time.Since(testStart)
})
var (
drift = time.Millisecond * 2
measured = time.Duration(tm.Max())
ceil = actualTime + drift
floor = actualTime - drift
)
if measured > ceil || measured < floor {
t.Errorf("tm.Max(): %v > %v || %v > %v\n", measured, ceil, measured, floor)
}
}

Expand Down

0 comments on commit 161336d

Please sign in to comment.