Fix race in TestGoCollectorMemStats
Related to #573 (but only partially fixes it). Signed-off-by: beorn7 <bjoern@rabenste.in>
This commit is contained in:
parent
2827f2a8d9
commit
709dc4b1de
|
@ -196,9 +196,11 @@ func TestGoCollectorMemStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
checkCollect(1)
|
checkCollect(1)
|
||||||
// Now msLast is set.
|
// Now msLast is set.
|
||||||
|
c.msMtx.Lock()
|
||||||
if want, got := uint64(1), c.msLast.Alloc; want != got {
|
if want, got := uint64(1), 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)
|
||||||
}
|
}
|
||||||
|
c.msMtx.Unlock()
|
||||||
|
|
||||||
// Scenario 2: msRead responds fast, previous memstats available, new
|
// Scenario 2: msRead responds fast, previous memstats available, new
|
||||||
// value collected.
|
// value collected.
|
||||||
|
@ -207,9 +209,11 @@ func TestGoCollectorMemStats(t *testing.T) {
|
||||||
}
|
}
|
||||||
checkCollect(2)
|
checkCollect(2)
|
||||||
// msLast is set, too.
|
// msLast is set, too.
|
||||||
|
c.msMtx.Lock()
|
||||||
if want, got := uint64(2), c.msLast.Alloc; want != got {
|
if want, got := uint64(2), 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)
|
||||||
}
|
}
|
||||||
|
c.msMtx.Unlock()
|
||||||
|
|
||||||
// Scenario 3: msRead responds slowly, previous memstats available, old
|
// Scenario 3: msRead responds slowly, previous memstats available, old
|
||||||
// value collected.
|
// value collected.
|
||||||
|
@ -220,9 +224,11 @@ func TestGoCollectorMemStats(t *testing.T) {
|
||||||
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(12 * time.Millisecond)
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
c.msMtx.Unlock()
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -231,7 +237,9 @@ func TestGoCollectorMemStats(t *testing.T) {
|
||||||
ms.Alloc = 4
|
ms.Alloc = 4
|
||||||
}
|
}
|
||||||
checkCollect(4)
|
checkCollect(4)
|
||||||
|
c.msMtx.Lock()
|
||||||
if want, got := uint64(4), c.msLast.Alloc; want != got {
|
if want, got := uint64(4), 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)
|
||||||
}
|
}
|
||||||
|
c.msMtx.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue