Skip to content

Commit

Permalink
Fix flaky test. (#5298)
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn authored Jun 21, 2023
1 parent 0f8cd6d commit 2aaa28c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/querier/blocks_finder_bucket_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,23 @@ func TestBucketScanBlocksFinder_StopWhileRunningTheInitialScanOnManyBlocks(t *te
}

// Mock the bucket to introduce a 1s sleep while syncing each block in the bucket.
bucket := &bucket.ClientMock{}
bucket.MockIter("", []string{"user-1"}, nil)
bucket.MockIter("user-1/", blockPaths, nil)
bucket.On("Exists", mock.Anything, mock.Anything).Return(false, nil).Run(func(args mock.Arguments) {
// We return the meta.json doesn't exist, but introduce a 1s delay for each call.
bkt := &bucket.ClientMock{}
bkt.MockIter("", []string{"user-1"}, nil)
bkt.MockIter("user-1/", blockPaths, nil)

// We return that all files don't exist, but introduce a 1s delay for each call.
sleep := func(_ mock.Arguments) {
time.Sleep(time.Second)
})
}
bkt.On("Exists", mock.Anything, mock.Anything).Return(false, nil).Run(sleep)
bkt.On("Get", mock.Anything, mock.Anything).Return(nil, bucket.ErrObjectDoesNotExist).Run(sleep)

cfg := prepareBucketScanBlocksFinderConfig()
cfg.CacheDir = t.TempDir()
cfg.MetasConcurrency = 1
cfg.TenantsConcurrency = 1

s := NewBucketScanBlocksFinder(cfg, bucket, nil, log.NewLogfmtLogger(os.Stdout), nil)
s := NewBucketScanBlocksFinder(cfg, bkt, nil, log.NewLogfmtLogger(os.Stdout), nil)

// Start the scanner, let it run for 1s and then issue a stop.
require.NoError(t, s.StartAsync(context.Background()))
Expand Down

0 comments on commit 2aaa28c

Please sign in to comment.