From eb6cdbcb5bb1354a8975df27de682fbb8f375299 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Fri, 23 Feb 2018 17:04:50 +0200 Subject: [PATCH] some test funcitons didn't cleanup after themselves. --- block_test.go | 3 ++- compact_test.go | 1 + db_test.go | 38 ++++++++++++++++---------------------- wal_test.go | 2 +- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/block_test.go b/block_test.go index 370047d5d..6aae98557 100644 --- a/block_test.go +++ b/block_test.go @@ -39,8 +39,9 @@ func TestBlockMetaMustNeverBeVersion2(t *testing.T) { } func TestSetCompactionFailed(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "test-tsdb") + tmpdir, err := ioutil.TempDir("", "test") testutil.Ok(t, err) + defer os.RemoveAll(tmpdir) b := createEmptyBlock(t, tmpdir) diff --git a/compact_test.go b/compact_test.go index 443aff0dc..116bb3d1a 100644 --- a/compact_test.go +++ b/compact_test.go @@ -328,6 +328,7 @@ func TestCompactionFailWillCleanUpTempDir(t *testing.T) { tmpdir, err := ioutil.TempDir("", "test") testutil.Ok(t, err) + defer os.RemoveAll(tmpdir) testutil.NotOk(t, compactor.write(tmpdir, &BlockMeta{}, erringBReader{})) _, err = os.Stat(filepath.Join(tmpdir, BlockMeta{}.ULID.String()) + ".tmp") diff --git a/db_test.go b/db_test.go index ef10edba6..2d5c2f3a8 100644 --- a/db_test.go +++ b/db_test.go @@ -351,6 +351,7 @@ func TestDB_Snapshot(t *testing.T) { // create snapshot snap, err := ioutil.TempDir("", "snap") testutil.Ok(t, err) + defer os.RemoveAll(snap) testutil.Ok(t, db.Snapshot(snap)) testutil.Ok(t, db.Close()) @@ -416,6 +417,7 @@ Outer: // create snapshot snap, err := ioutil.TempDir("", "snap") testutil.Ok(t, err) + defer os.RemoveAll(snap) testutil.Ok(t, db.Snapshot(snap)) testutil.Ok(t, db.Close()) @@ -629,23 +631,21 @@ func TestDB_e2e(t *testing.T) { } func TestWALFlushedOnDBClose(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "test") - testutil.Ok(t, err) - defer os.RemoveAll(tmpdir) + db, close := openTestDB(t, nil) + defer close() - db, err := Open(tmpdir, nil, nil, nil) - testutil.Ok(t, err) + dirDb := db.Dir() lbls := labels.Labels{labels.Label{Name: "labelname", Value: "labelvalue"}} app := db.Appender() - _, err = app.Add(lbls, 0, 1) + _, err := app.Add(lbls, 0, 1) testutil.Ok(t, err) testutil.Ok(t, app.Commit()) testutil.Ok(t, db.Close()) - db, err = Open(tmpdir, nil, nil, nil) + db, err = Open(dirDb, nil, nil, nil) testutil.Ok(t, err) defer db.Close() @@ -688,6 +688,7 @@ func TestTombstoneClean(t *testing.T) { // create snapshot snap, err := ioutil.TempDir("", "snap") testutil.Ok(t, err) + defer os.RemoveAll(snap) testutil.Ok(t, db.Snapshot(snap)) testutil.Ok(t, db.Close()) @@ -751,16 +752,13 @@ func TestTombstoneClean(t *testing.T) { } func TestDB_Retention(t *testing.T) { - tmpdir, _ := ioutil.TempDir("", "test") - defer os.RemoveAll(tmpdir) - - db, err := Open(tmpdir, nil, nil, nil) - testutil.Ok(t, err) + db, close := openTestDB(t, nil) + defer close() lbls := labels.Labels{labels.Label{Name: "labelname", Value: "labelvalue"}} app := db.Appender() - _, err = app.Add(lbls, 0, 1) + _, err := app.Add(lbls, 0, 1) testutil.Ok(t, err) testutil.Ok(t, app.Commit()) @@ -768,9 +766,9 @@ func TestDB_Retention(t *testing.T) { // TODO(gouthamve): Add a method to compact headblock. snap, err := ioutil.TempDir("", "snap") testutil.Ok(t, err) + defer os.RemoveAll(snap) testutil.Ok(t, db.Snapshot(snap)) testutil.Ok(t, db.Close()) - defer os.RemoveAll(snap) // reopen DB from snapshot db, err = Open(snap, nil, nil, nil) @@ -786,9 +784,9 @@ func TestDB_Retention(t *testing.T) { // Snapshot again to create another block. snap, err = ioutil.TempDir("", "snap") testutil.Ok(t, err) + defer os.RemoveAll(snap) testutil.Ok(t, db.Snapshot(snap)) testutil.Ok(t, db.Close()) - defer os.RemoveAll(snap) // reopen DB from snapshot db, err = Open(snap, nil, nil, &Options{ @@ -809,12 +807,8 @@ func TestDB_Retention(t *testing.T) { } func TestNotMatcherSelectsLabelsUnsetSeries(t *testing.T) { - tmpdir, _ := ioutil.TempDir("", "test") - defer os.RemoveAll(tmpdir) - - db, err := Open(tmpdir, nil, nil, nil) - testutil.Ok(t, err) - defer db.Close() + db, close := openTestDB(t, nil) + defer close() labelpairs := []labels.Labels{ labels.FromStrings("a", "abcd", "b", "abcde"), @@ -823,7 +817,7 @@ func TestNotMatcherSelectsLabelsUnsetSeries(t *testing.T) { app := db.Appender() for _, lbls := range labelpairs { - _, err = app.Add(lbls, 0, 1) + _, err := app.Add(lbls, 0, 1) testutil.Ok(t, err) } testutil.Ok(t, app.Commit()) diff --git a/wal_test.go b/wal_test.go index c4c0f0366..c6552eb62 100644 --- a/wal_test.go +++ b/wal_test.go @@ -78,7 +78,7 @@ func TestSegmentWAL_Truncate(t *testing.T) { dir, err := ioutil.TempDir("", "test_wal_log_truncate") testutil.Ok(t, err) - // defer os.RemoveAll(dir) + defer os.RemoveAll(dir) w, err := OpenSegmentWAL(dir, nil, 0, nil) testutil.Ok(t, err)