Skip to content

Commit fe90eea

Browse files
committed
Attempt to fix flakiness of TestGoCollectorMemStats
This is really lame as it essentially just uses longer times to wait. The test is still timing-dependent and thus could still theoretically fail with unlucky scheduling. However, we are testing something that _is_ about timing. Turning this all into something not timing-dependent would be first quite involved and second might defeat the purpose of testing code that is inherently about timing. Let's see how this works out in practice. Signed-off-by: beorn7 <[email protected]>
1 parent b46e6ec commit fe90eea

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

prometheus/go_collector_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ func TestGoCollectorMemStats(t *testing.T) {
184184
}
185185
}
186186

187-
// Speed up the timing to make the tast faster.
188-
c.msMaxWait = time.Millisecond
189-
c.msMaxAge = 10 * time.Millisecond
187+
// Speed up the timing to make the test faster.
188+
c.msMaxWait = 5 * time.Millisecond
189+
c.msMaxAge = 50 * time.Millisecond
190190

191191
// Scenario 1: msRead responds slowly, no previous memstats available,
192192
// msRead is executed anyway.
193193
c.msRead = func(ms *runtime.MemStats) {
194-
time.Sleep(3 * time.Millisecond)
194+
time.Sleep(20 * time.Millisecond)
195195
ms.Alloc = 1
196196
}
197197
checkCollect(1)
@@ -218,12 +218,12 @@ func TestGoCollectorMemStats(t *testing.T) {
218218
// Scenario 3: msRead responds slowly, previous memstats available, old
219219
// value collected.
220220
c.msRead = func(ms *runtime.MemStats) {
221-
time.Sleep(3 * time.Millisecond)
221+
time.Sleep(20 * time.Millisecond)
222222
ms.Alloc = 3
223223
}
224224
checkCollect(2)
225225
// After waiting, new value is still set in msLast.
226-
time.Sleep(12 * time.Millisecond)
226+
time.Sleep(80 * time.Millisecond)
227227
c.msMtx.Lock()
228228
if want, got := uint64(3), c.msLast.Alloc; want != got {
229229
t.Errorf("unexpected of msLast.Alloc, want %d, got %d", want, got)
@@ -233,7 +233,7 @@ func TestGoCollectorMemStats(t *testing.T) {
233233
// Scenario 4: msRead responds slowly, previous memstats is too old, new
234234
// value collected.
235235
c.msRead = func(ms *runtime.MemStats) {
236-
time.Sleep(3 * time.Millisecond)
236+
time.Sleep(20 * time.Millisecond)
237237
ms.Alloc = 4
238238
}
239239
checkCollect(4)

0 commit comments

Comments
 (0)