TestDisableAutoCompactions checks that we can disable and enable the auto compaction. This is needed for unit tests that rely on checking state before and after a compaction.
(t *testing.T)
| 1319 | // This is needed for unit tests that rely on |
| 1320 | // checking state before and after a compaction. |
| 1321 | func TestDisableAutoCompactions(t *testing.T) { |
| 1322 | db := newTestDB(t) |
| 1323 | |
| 1324 | blockRange := db.compactor.(*LeveledCompactor).ranges[0] |
| 1325 | label := labels.FromStrings("foo", "bar") |
| 1326 | |
| 1327 | // Trigger a compaction to check that it was skipped and |
| 1328 | // no new blocks were created when compaction is disabled. |
| 1329 | db.DisableCompactions() |
| 1330 | app := db.Appender(context.Background()) |
| 1331 | for i := range int64(3) { |
| 1332 | _, err := app.Append(0, label, i*blockRange, 0) |
| 1333 | require.NoError(t, err) |
| 1334 | _, err = app.Append(0, label, i*blockRange+1000, 0) |
| 1335 | require.NoError(t, err) |
| 1336 | } |
| 1337 | require.NoError(t, app.Commit()) |
| 1338 | |
| 1339 | select { |
| 1340 | case db.compactc <- struct{}{}: |
| 1341 | default: |
| 1342 | } |
| 1343 | |
| 1344 | for range 10 { |
| 1345 | if prom_testutil.ToFloat64(db.metrics.compactionsSkipped) > 0.0 { |
| 1346 | break |
| 1347 | } |
| 1348 | time.Sleep(10 * time.Millisecond) |
| 1349 | } |
| 1350 | |
| 1351 | require.Greater(t, prom_testutil.ToFloat64(db.metrics.compactionsSkipped), 0.0, "No compaction was skipped after the set timeout.") |
| 1352 | require.Empty(t, db.blocks) |
| 1353 | |
| 1354 | // Enable the compaction, trigger it and check that the block is persisted. |
| 1355 | db.EnableCompactions() |
| 1356 | select { |
| 1357 | case db.compactc <- struct{}{}: |
| 1358 | default: |
| 1359 | } |
| 1360 | for range 100 { |
| 1361 | if len(db.Blocks()) > 0 { |
| 1362 | break |
| 1363 | } |
| 1364 | time.Sleep(100 * time.Millisecond) |
| 1365 | } |
| 1366 | require.NotEmpty(t, db.Blocks(), "No block was persisted after the set timeout.") |
| 1367 | } |
| 1368 | |
| 1369 | // TestCancelCompactions ensures that when the db is closed |
| 1370 | // any running compaction is cancelled to unblock closing the db. |
nothing calls this directly
no test coverage detected
searching dependent graphs…