mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
metrics: make flawed test less flawed (#20818)
This commit is contained in:
parent
9fee8a72eb
commit
47ce406a4a
1 changed files with 17 additions and 4 deletions
|
|
@ -45,10 +45,23 @@ func TestTimerStop(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimerFunc(t *testing.T) {
|
func TestTimerFunc(t *testing.T) {
|
||||||
tm := NewTimer()
|
var (
|
||||||
tm.Time(func() { time.Sleep(50e6) })
|
tm = NewTimer()
|
||||||
if max := tm.Max(); 35e6 > max || max > 95e6 {
|
testStart = time.Now()
|
||||||
t.Errorf("tm.Max(): 35e6 > %v || %v > 95e6\n", max, max)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue