Skip to content

Commit

Permalink
metrics: fix flaky Example metrics test (ethereum#16222)
Browse files Browse the repository at this point in the history
* metrics: add sleep to test in order to get predictable output

* metrics: relax constraints on timer test
  • Loading branch information
nonsense authored and karalabe committed Mar 1, 2018
1 parent 5a150e1 commit 3ca3fff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"sync"
"testing"
"time"
)

const FANOUT = 128
Expand Down Expand Up @@ -114,7 +115,7 @@ func Example() {

// Threadsafe registration
t := GetOrRegisterTimer("db.get.latency", nil)
t.Time(func() {})
t.Time(func() { time.Sleep(10 * time.Millisecond) })
t.Update(1)

fmt.Println(c.Count())
Expand Down
4 changes: 2 additions & 2 deletions metrics/timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestTimerStop(t *testing.T) {
func TestTimerFunc(t *testing.T) {
tm := NewTimer()
tm.Time(func() { time.Sleep(50e6) })
if max := tm.Max(); 45e6 > max || max > 55e6 {
t.Errorf("tm.Max(): 45e6 > %v || %v > 55e6\n", max, max)
if max := tm.Max(); 35e6 > max || max > 95e6 {
t.Errorf("tm.Max(): 35e6 > %v || %v > 95e6\n", max, max)
}
}

Expand Down

0 comments on commit 3ca3fff

Please sign in to comment.