From c57a74eb4de8e05e0fd81a269ad689db1c3675c5 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Wed, 28 Oct 2020 12:01:20 +0530 Subject: [PATCH] Fix flaky TestIngester_flushing Signed-off-by: Ganesh Vernekar --- pkg/ingester/ingester_v2_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/ingester/ingester_v2_test.go b/pkg/ingester/ingester_v2_test.go index a72c6461071..f5255455a53 100644 --- a/pkg/ingester/ingester_v2_test.go +++ b/pkg/ingester/ingester_v2_test.go @@ -1858,6 +1858,15 @@ func TestIngester_flushing(t *testing.T) { i.FlushHandler(httptest.NewRecorder(), httptest.NewRequest("POST", "/flush", nil)) // Flush handler only triggers compactions, but doesn't wait for them to finish. Let's wait for a moment, and then verify. + test.Poll(t, 1*time.Second, true, func() interface{} { + db := i.getTSDB(userID) + if db == nil { + return false + } + return db.Head().NumSeries() == 0 + }) + + // The above waiting only ensures compaction, waiting another second to register the Sync call. time.Sleep(1 * time.Second) verifyCompactedHead(t, i, true) @@ -1888,17 +1897,20 @@ func TestIngester_flushing(t *testing.T) { i.FlushHandler(httptest.NewRecorder(), httptest.NewRequest("POST", "/flush", nil)) - // Wait for compaction to finish. - test.Poll(t, 5*time.Second, true, func() interface{} { + // Flush handler only triggers compactions, but doesn't wait for them to finish. Let's wait for a moment, and then verify. + test.Poll(t, 1*time.Second, true, func() interface{} { db := i.getTSDB(userID) if db == nil { return false } - - h := db.Head() - return h.NumSeries() == 0 + return db.Head().NumSeries() == 0 }) + // The above waiting only ensures compaction, waiting another second to register the Sync call. + time.Sleep(1 * time.Second) + + verifyCompactedHead(t, i, true) + m.AssertNumberOfCalls(t, "Sync", 1) userDB := i.getTSDB(userID)