diff --git a/tsdb/db_test.go b/tsdb/db_test.go index 655cf9dac..ce772acdd 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -1281,38 +1281,40 @@ func TestTombstoneCleanRetentionLimitsRace(t *testing.T) { // // That is something tricky to trigger, so let's try several times just to make sure. for i := 0; i < 20; i++ { - db := openTestDB(t, opts, nil) - totalBlocks := 20 - dbDir := db.Dir() - // Generate some blocks with old mint (near epoch). - for j := 0; j < totalBlocks; j++ { - blockDir := createBlock(t, dbDir, genSeries(10, 1, int64(j), int64(j)+1)) - block, err := OpenBlock(nil, blockDir, nil) - require.NoError(t, err) - // Cover block with tombstones so it can be deleted with CleanTombstones() as well. - tomb := tombstones.NewMemTombstones() - tomb.AddInterval(0, tombstones.Interval{Mint: int64(j), Maxt: int64(j) + 1}) - block.tombstones = tomb + t.Run(fmt.Sprintf("iteration%d", i), func(t *testing.T) { + db := openTestDB(t, opts, nil) + totalBlocks := 20 + dbDir := db.Dir() + // Generate some blocks with old mint (near epoch). + for j := 0; j < totalBlocks; j++ { + blockDir := createBlock(t, dbDir, genSeries(10, 1, int64(j), int64(j)+1)) + block, err := OpenBlock(nil, blockDir, nil) + require.NoError(t, err) + // Cover block with tombstones so it can be deleted with CleanTombstones() as well. + tomb := tombstones.NewMemTombstones() + tomb.AddInterval(0, tombstones.Interval{Mint: int64(j), Maxt: int64(j) + 1}) + block.tombstones = tomb - db.blocks = append(db.blocks, block) - } + db.blocks = append(db.blocks, block) + } - wg.Add(2) - // Run reload and CleanTombstones together, with a small time window randomization - go func() { - defer wg.Done() - time.Sleep(time.Duration(rand.Float64() * 100 * float64(time.Millisecond))) - require.NoError(t, db.reloadBlocks()) - }() - go func() { - defer wg.Done() - time.Sleep(time.Duration(rand.Float64() * 100 * float64(time.Millisecond))) - require.NoError(t, db.CleanTombstones()) - }() + wg.Add(2) + // Run reload and CleanTombstones together, with a small time window randomization + go func() { + defer wg.Done() + time.Sleep(time.Duration(rand.Float64() * 100 * float64(time.Millisecond))) + require.NoError(t, db.reloadBlocks()) + }() + go func() { + defer wg.Done() + time.Sleep(time.Duration(rand.Float64() * 100 * float64(time.Millisecond))) + require.NoError(t, db.CleanTombstones()) + }() - wg.Wait() + wg.Wait() - require.NoError(t, db.Close()) + require.NoError(t, db.Close()) + }) } }