From 70482e6ee4288e11e986243f5ab35b7b387a0f3e Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Wed, 6 May 2026 07:09:57 +0000 Subject: [PATCH] fix(compactor): Fix flaky TestBlocksCleaner_ShouldRemoveBlocksOutsideRetentionPeriod Switch from filesystem bucket to in-memory bucket in this test. The filesystem bucket's Upload is non-atomic (os.Create truncates, then io.Copy writes), creating a race window where the HeartBeat goroutine's write can be observed as an empty file by a concurrent read. The in-memory bucket's Upload is atomic (mutex-protected), eliminating the race. Signed-off-by: Ben Ye --- pkg/compactor/blocks_cleaner_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/compactor/blocks_cleaner_test.go b/pkg/compactor/blocks_cleaner_test.go index ea247392578..4e758f66662 100644 --- a/pkg/compactor/blocks_cleaner_test.go +++ b/pkg/compactor/blocks_cleaner_test.go @@ -16,6 +16,7 @@ import ( prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/thanos-io/objstore" "github.com/thanos-io/thanos/pkg/block" "github.com/thanos-io/thanos/pkg/block/metadata" @@ -658,8 +659,7 @@ func TestBlocksCleaner_ListBlocksOutsideRetentionPeriod(t *testing.T) { } func TestBlocksCleaner_ShouldRemoveBlocksOutsideRetentionPeriod(t *testing.T) { - bucketClient, _ := cortex_testutil.PrepareFilesystemBucket(t) - bucketClient = bucketindex.BucketWithGlobalMarkers(bucketClient) + bucketClient := bucketindex.BucketWithGlobalMarkers(objstore.WithNoopInstr(objstore.NewInMemBucket())) ts := func(hours int) int64 { return time.Now().Add(time.Duration(hours)*time.Hour).Unix() * 1000