diff --git a/storage/remote/queue_manager_test.go b/storage/remote/queue_manager_test.go index 39861a16f..59cf64e85 100644 --- a/storage/remote/queue_manager_test.go +++ b/storage/remote/queue_manager_test.go @@ -60,7 +60,9 @@ func TestSampleDelivery(t *testing.T) { dir, err := ioutil.TempDir("", "TestSampleDeliver") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) @@ -89,7 +91,9 @@ func TestSampleDeliveryTimeout(t *testing.T) { dir, err := ioutil.TempDir("", "TestSampleDeliveryTimeout") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) @@ -130,7 +134,9 @@ func TestSampleDeliveryOrder(t *testing.T) { dir, err := ioutil.TempDir("", "TestSampleDeliveryOrder") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), config.DefaultQueueConfig, nil, nil, c, defaultFlushDeadline) @@ -149,7 +155,9 @@ func TestShutdown(t *testing.T) { dir, err := ioutil.TempDir("", "TestShutdown") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") @@ -188,7 +196,9 @@ func TestSeriesReset(t *testing.T) { dir, err := ioutil.TempDir("", "TestSeriesReset") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), config.DefaultQueueConfig, nil, nil, c, deadline) @@ -218,7 +228,9 @@ func TestReshard(t *testing.T) { dir, err := ioutil.TempDir("", "TestReshard") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) @@ -616,7 +628,9 @@ func TestCalculateDesiredShards(t *testing.T) { dir, err := ioutil.TempDir("", "TestCalculateDesiredShards") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() metrics := newQueueManagerMetrics(nil, "", "") samplesIn := newEWMARate(ewmaWeight, shardUpdateDuration) diff --git a/storage/remote/write_test.go b/storage/remote/write_test.go index 69b710aa5..e864785e0 100644 --- a/storage/remote/write_test.go +++ b/storage/remote/write_test.go @@ -43,7 +43,9 @@ var cfg = config.RemoteWriteConfig{ func TestNoDuplicateWriteConfigs(t *testing.T) { dir, err := ioutil.TempDir("", "TestNoDuplicateWriteConfigs") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() cfg1 := config.RemoteWriteConfig{ Name: "write-1", @@ -129,7 +131,9 @@ func TestNoDuplicateWriteConfigs(t *testing.T) { func TestRestartOnNameChange(t *testing.T) { dir, err := ioutil.TempDir("", "TestRestartOnNameChange") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() hash, err := toHash(cfg) testutil.Ok(t, err) @@ -158,7 +162,9 @@ func TestRestartOnNameChange(t *testing.T) { func TestUpdateWithRegisterer(t *testing.T) { dir, err := ioutil.TempDir("", "TestRestartWithRegisterer") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Millisecond) c1 := &config.RemoteWriteConfig{ @@ -200,7 +206,9 @@ func TestUpdateWithRegisterer(t *testing.T) { func TestWriteStorageLifecycle(t *testing.T) { dir, err := ioutil.TempDir("", "TestWriteStorageLifecycle") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) conf := &config.Config{ @@ -219,7 +227,9 @@ func TestWriteStorageLifecycle(t *testing.T) { func TestUpdateExternalLabels(t *testing.T) { dir, err := ioutil.TempDir("", "TestUpdateExternalLabels") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Second) @@ -250,7 +260,9 @@ func TestUpdateExternalLabels(t *testing.T) { func TestWriteStorageApplyConfigsIdempotent(t *testing.T) { dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsIdempotent") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) @@ -284,7 +296,9 @@ func TestWriteStorageApplyConfigsIdempotent(t *testing.T) { func TestWriteStorageApplyConfigsPartialUpdate(t *testing.T) { dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsPartialUpdate") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) diff --git a/tsdb/db_test.go b/tsdb/db_test.go index f68c6c40a..805f66714 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -2508,7 +2508,9 @@ func TestDBReadOnly_FlushWAL(t *testing.T) { func TestDBCannotSeePartialCommits(t *testing.T) { tmpdir, _ := ioutil.TempDir("", "test") - defer os.RemoveAll(tmpdir) + defer func() { + testutil.Ok(t, os.RemoveAll(tmpdir)) + }() db, err := Open(tmpdir, nil, nil, nil) testutil.Ok(t, err) @@ -2575,7 +2577,9 @@ func TestDBCannotSeePartialCommits(t *testing.T) { func TestDBQueryDoesntSeeAppendsAfterCreation(t *testing.T) { tmpdir, _ := ioutil.TempDir("", "test") - defer os.RemoveAll(tmpdir) + defer func() { + testutil.Ok(t, os.RemoveAll(tmpdir)) + }() db, err := Open(tmpdir, nil, nil, nil) testutil.Ok(t, err) diff --git a/tsdb/wal/watcher_test.go b/tsdb/wal/watcher_test.go index e4615eff4..d45beb419 100644 --- a/tsdb/wal/watcher_test.go +++ b/tsdb/wal/watcher_test.go @@ -100,7 +100,9 @@ func TestTailSamples(t *testing.T) { dir, err := ioutil.TempDir("", "readCheckpoint") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) @@ -109,6 +111,9 @@ func TestTailSamples(t *testing.T) { enc := record.Encoder{} w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) testutil.Ok(t, err) + defer func() { + testutil.Ok(t, w.Close()) + }() // Write to the initial segment then checkpoint. for i := 0; i < seriesCount; i++ { @@ -174,13 +179,18 @@ func TestReadToEndNoCheckpoint(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) { dir, err := ioutil.TempDir("", "readToEnd_noCheckpoint") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) testutil.Ok(t, err) w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) testutil.Ok(t, err) + defer func() { + testutil.Ok(t, w.Close()) + }() var recs [][]byte @@ -242,7 +252,9 @@ func TestReadToEndWithCheckpoint(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) { dir, err := ioutil.TempDir("", "readToEnd_withCheckpoint") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) @@ -251,6 +263,9 @@ func TestReadToEndWithCheckpoint(t *testing.T) { enc := record.Encoder{} w, err := NewSize(nil, nil, wdir, segmentSize, compress) testutil.Ok(t, err) + defer func() { + testutil.Ok(t, w.Close()) + }() // Write to the initial segment then checkpoint. for i := 0; i < seriesCount; i++ { @@ -326,7 +341,9 @@ func TestReadCheckpoint(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) { dir, err := ioutil.TempDir("", "readCheckpoint") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) @@ -337,6 +354,9 @@ func TestReadCheckpoint(t *testing.T) { enc := record.Encoder{} w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) testutil.Ok(t, err) + defer func() { + testutil.Ok(t, w.Close()) + }() // Write to the initial segment then checkpoint. for i := 0; i < seriesCount; i++ { @@ -393,7 +413,9 @@ func TestReadCheckpointMultipleSegments(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) { dir, err := ioutil.TempDir("", "readCheckpoint") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) @@ -473,7 +495,9 @@ func TestCheckpointSeriesReset(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", tc.compress), func(t *testing.T) { dir, err := ioutil.TempDir("", "seriesReset") testutil.Ok(t, err) - defer os.RemoveAll(dir) + defer func() { + testutil.Ok(t, os.RemoveAll(dir)) + }() wdir := path.Join(dir, "wal") err = os.Mkdir(wdir, 0777) @@ -482,6 +506,9 @@ func TestCheckpointSeriesReset(t *testing.T) { enc := record.Encoder{} w, err := NewSize(nil, nil, wdir, segmentSize, tc.compress) testutil.Ok(t, err) + defer func() { + testutil.Ok(t, w.Close()) + }() // Write to the initial segment, then checkpoint later. for i := 0; i < seriesCount; i++ {