Skip to content

Commit 35919e4

Browse files
authored
Reduce flakiness on chunk flush tests (#4386)
The thinking was: we are flushing every 20ms, so wait 40ms to be sure that one cycle has happened. However if you log the times at which things happen, it is fairly common to see 100ms delay on the flush ticker. So wait a lot longer to be sure. Also close down the ingester that we created for the test, and improve the error message on failure. Signed-off-by: Bryan Boreham <[email protected]>
1 parent e274ae0 commit 35919e4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/ingester/ingester_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (s *testStore) checkData(t *testing.T, userIDs []string, testData map[strin
9494
res, err := chunk.ChunksToMatrix(context.Background(), s.chunks[userID], model.Time(0), model.Time(math.MaxInt64))
9595
require.NoError(t, err)
9696
sort.Sort(res)
97-
assert.Equal(t, testData[userID], res)
97+
assert.Equal(t, testData[userID], res, "userID %s", userID)
9898
}
9999
}
100100

@@ -388,7 +388,7 @@ func TestIngesterIdleFlush(t *testing.T) {
388388
userIDs, testData := pushTestSamples(t, ing, 4, 100, 0)
389389

390390
// wait beyond idle time so samples flush
391-
time.Sleep(cfg.MaxChunkIdle * 2)
391+
time.Sleep(cfg.MaxChunkIdle * 3)
392392

393393
store.checkData(t, userIDs, testData)
394394

@@ -410,6 +410,8 @@ func TestIngesterIdleFlush(t *testing.T) {
410410
require.NoError(t, err)
411411
assert.Equal(t, model.Matrix{}, res)
412412
}
413+
414+
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), ing))
413415
}
414416

415417
func TestIngesterSpreadFlush(t *testing.T) {
@@ -426,10 +428,13 @@ func TestIngesterSpreadFlush(t *testing.T) {
426428
_, _ = pushTestSamples(t, ing, 4, 1, int(cfg.MaxChunkAge.Seconds()-1)*1000)
427429

428430
// wait beyond flush time so first set of samples should be sent to store
429-
time.Sleep(cfg.FlushCheckPeriod * 2)
431+
// (you'd think a shorter wait, like period*2, would work, but Go timers are not reliable enough for that)
432+
time.Sleep(cfg.FlushCheckPeriod * 10)
430433

431434
// check the first set of samples has been sent to the store
432435
store.checkData(t, userIDs, testData)
436+
437+
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), ing))
433438
}
434439

435440
type stream struct {

0 commit comments

Comments
 (0)