Merge pull request #588 from prometheus/beorn7/test

Attempt to fix flakiness of TestGoCollectorMemStats
This commit is contained in:
Björn Rabenstein 2019-05-26 23:20:33 +02:00 committed by GitHub
commit 388f9869ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -184,14 +184,14 @@ func TestGoCollectorMemStats(t *testing.T) {
} }
} }
// Speed up the timing to make the tast faster. // Speed up the timing to make the test faster.
c.msMaxWait = time.Millisecond c.msMaxWait = 5 * time.Millisecond
c.msMaxAge = 10 * time.Millisecond c.msMaxAge = 50 * time.Millisecond
// Scenario 1: msRead responds slowly, no previous memstats available, // Scenario 1: msRead responds slowly, no previous memstats available,
// msRead is executed anyway. // msRead is executed anyway.
c.msRead = func(ms *runtime.MemStats) { c.msRead = func(ms *runtime.MemStats) {
time.Sleep(3 * time.Millisecond) time.Sleep(20 * time.Millisecond)
ms.Alloc = 1 ms.Alloc = 1
} }
checkCollect(1) checkCollect(1)
@ -218,12 +218,12 @@ func TestGoCollectorMemStats(t *testing.T) {
// Scenario 3: msRead responds slowly, previous memstats available, old // Scenario 3: msRead responds slowly, previous memstats available, old
// value collected. // value collected.
c.msRead = func(ms *runtime.MemStats) { c.msRead = func(ms *runtime.MemStats) {
time.Sleep(3 * time.Millisecond) time.Sleep(20 * time.Millisecond)
ms.Alloc = 3 ms.Alloc = 3
} }
checkCollect(2) checkCollect(2)
// After waiting, new value is still set in msLast. // After waiting, new value is still set in msLast.
time.Sleep(12 * time.Millisecond) time.Sleep(80 * time.Millisecond)
c.msMtx.Lock() c.msMtx.Lock()
if want, got := uint64(3), c.msLast.Alloc; want != got { if want, got := uint64(3), c.msLast.Alloc; want != got {
t.Errorf("unexpected of msLast.Alloc, want %d, got %d", want, got) t.Errorf("unexpected of msLast.Alloc, want %d, got %d", want, got)
@ -233,7 +233,7 @@ func TestGoCollectorMemStats(t *testing.T) {
// Scenario 4: msRead responds slowly, previous memstats is too old, new // Scenario 4: msRead responds slowly, previous memstats is too old, new
// value collected. // value collected.
c.msRead = func(ms *runtime.MemStats) { c.msRead = func(ms *runtime.MemStats) {
time.Sleep(3 * time.Millisecond) time.Sleep(20 * time.Millisecond)
ms.Alloc = 4 ms.Alloc = 4
} }
checkCollect(4) checkCollect(4)