metrics: fix flaky Example metrics test (#16222)

* metrics: add sleep to test in order to get predictable output

* metrics: relax constraints on timer test
pull/16044/head
Anton Evangelatov 7 years ago committed by Péter Szilágyi
parent 5a150e1b77
commit 3ca3fffdf0
  1. 3
      metrics/metrics_test.go
  2. 4
      metrics/timer_test.go

@ -6,6 +6,7 @@ import (
"log" "log"
"sync" "sync"
"testing" "testing"
"time"
) )
const FANOUT = 128 const FANOUT = 128
@ -114,7 +115,7 @@ func Example() {
// Threadsafe registration // Threadsafe registration
t := GetOrRegisterTimer("db.get.latency", nil) t := GetOrRegisterTimer("db.get.latency", nil)
t.Time(func() {}) t.Time(func() { time.Sleep(10 * time.Millisecond) })
t.Update(1) t.Update(1)
fmt.Println(c.Count()) fmt.Println(c.Count())

@ -47,8 +47,8 @@ func TestTimerStop(t *testing.T) {
func TestTimerFunc(t *testing.T) { func TestTimerFunc(t *testing.T) {
tm := NewTimer() tm := NewTimer()
tm.Time(func() { time.Sleep(50e6) }) tm.Time(func() { time.Sleep(50e6) })
if max := tm.Max(); 45e6 > max || max > 55e6 { if max := tm.Max(); 35e6 > max || max > 95e6 {
t.Errorf("tm.Max(): 45e6 > %v || %v > 55e6\n", max, max) t.Errorf("tm.Max(): 35e6 > %v || %v > 95e6\n", max, max)
} }
} }

Loading…
Cancel
Save