Skip to content

Commit 3ca3fff

Browse files
nonsensekaralabe
authored andcommitted
metrics: fix flaky Example metrics test (#16222)
* metrics: add sleep to test in order to get predictable output * metrics: relax constraints on timer test
1 parent 5a150e1 commit 3ca3fff

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

metrics/metrics_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"sync"
88
"testing"
9+
"time"
910
)
1011

1112
const FANOUT = 128
@@ -114,7 +115,7 @@ func Example() {
114115

115116
// Threadsafe registration
116117
t := GetOrRegisterTimer("db.get.latency", nil)
117-
t.Time(func() {})
118+
t.Time(func() { time.Sleep(10 * time.Millisecond) })
118119
t.Update(1)
119120

120121
fmt.Println(c.Count())

metrics/timer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func TestTimerStop(t *testing.T) {
4747
func TestTimerFunc(t *testing.T) {
4848
tm := NewTimer()
4949
tm.Time(func() { time.Sleep(50e6) })
50-
if max := tm.Max(); 45e6 > max || max > 55e6 {
51-
t.Errorf("tm.Max(): 45e6 > %v || %v > 55e6\n", max, max)
50+
if max := tm.Max(); 35e6 > max || max > 95e6 {
51+
t.Errorf("tm.Max(): 35e6 > %v || %v > 95e6\n", max, max)
5252
}
5353
}
5454

0 commit comments

Comments
 (0)