Browse Source

add os.RemoveAll err verification (#7540)

* add os.RemoveAll err verification for watcher_test

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

* add os.RemoveAll err verification for db_test

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

* add os.RemoveAll err verification for write_test

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

* add os.RemoveAll err verification for queue_manager_test

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>

* tsdb/wal/watcher_test: add close operation before delete

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
pull/7599/head
Zhou Hao 4 years ago committed by GitHub
parent
commit
ddedf454d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      storage/remote/queue_manager_test.go
  2. 28
      storage/remote/write_test.go
  3. 8
      tsdb/db_test.go
  4. 39
      tsdb/wal/watcher_test.go

28
storage/remote/queue_manager_test.go

@ -60,7 +60,9 @@ func TestSampleDelivery(t *testing.T) {
dir, err := ioutil.TempDir("", "TestSampleDeliver") dir, err := ioutil.TempDir("", "TestSampleDeliver")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) 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") dir, err := ioutil.TempDir("", "TestSampleDeliveryTimeout")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) 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") dir, err := ioutil.TempDir("", "TestSampleDeliveryOrder")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), config.DefaultQueueConfig, nil, nil, c, defaultFlushDeadline) 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") dir, err := ioutil.TempDir("", "TestShutdown")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
@ -188,7 +196,9 @@ func TestSeriesReset(t *testing.T) {
dir, err := ioutil.TempDir("", "TestSeriesReset") dir, err := ioutil.TempDir("", "TestSeriesReset")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), config.DefaultQueueConfig, nil, nil, c, deadline) 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") dir, err := ioutil.TempDir("", "TestReshard")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
m := NewQueueManager(metrics, nil, nil, nil, dir, newEWMARate(ewmaWeight, shardUpdateDuration), cfg, nil, nil, c, defaultFlushDeadline) 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") dir, err := ioutil.TempDir("", "TestCalculateDesiredShards")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
metrics := newQueueManagerMetrics(nil, "", "") metrics := newQueueManagerMetrics(nil, "", "")
samplesIn := newEWMARate(ewmaWeight, shardUpdateDuration) samplesIn := newEWMARate(ewmaWeight, shardUpdateDuration)

28
storage/remote/write_test.go

@ -43,7 +43,9 @@ var cfg = config.RemoteWriteConfig{
func TestNoDuplicateWriteConfigs(t *testing.T) { func TestNoDuplicateWriteConfigs(t *testing.T) {
dir, err := ioutil.TempDir("", "TestNoDuplicateWriteConfigs") dir, err := ioutil.TempDir("", "TestNoDuplicateWriteConfigs")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
cfg1 := config.RemoteWriteConfig{ cfg1 := config.RemoteWriteConfig{
Name: "write-1", Name: "write-1",
@ -129,7 +131,9 @@ func TestNoDuplicateWriteConfigs(t *testing.T) {
func TestRestartOnNameChange(t *testing.T) { func TestRestartOnNameChange(t *testing.T) {
dir, err := ioutil.TempDir("", "TestRestartOnNameChange") dir, err := ioutil.TempDir("", "TestRestartOnNameChange")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
hash, err := toHash(cfg) hash, err := toHash(cfg)
testutil.Ok(t, err) testutil.Ok(t, err)
@ -158,7 +162,9 @@ func TestRestartOnNameChange(t *testing.T) {
func TestUpdateWithRegisterer(t *testing.T) { func TestUpdateWithRegisterer(t *testing.T) {
dir, err := ioutil.TempDir("", "TestRestartWithRegisterer") dir, err := ioutil.TempDir("", "TestRestartWithRegisterer")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Millisecond) s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Millisecond)
c1 := &config.RemoteWriteConfig{ c1 := &config.RemoteWriteConfig{
@ -200,7 +206,9 @@ func TestUpdateWithRegisterer(t *testing.T) {
func TestWriteStorageLifecycle(t *testing.T) { func TestWriteStorageLifecycle(t *testing.T) {
dir, err := ioutil.TempDir("", "TestWriteStorageLifecycle") dir, err := ioutil.TempDir("", "TestWriteStorageLifecycle")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline)
conf := &config.Config{ conf := &config.Config{
@ -219,7 +227,9 @@ func TestWriteStorageLifecycle(t *testing.T) {
func TestUpdateExternalLabels(t *testing.T) { func TestUpdateExternalLabels(t *testing.T) {
dir, err := ioutil.TempDir("", "TestUpdateExternalLabels") dir, err := ioutil.TempDir("", "TestUpdateExternalLabels")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Second) s := NewWriteStorage(nil, prometheus.NewRegistry(), dir, time.Second)
@ -250,7 +260,9 @@ func TestUpdateExternalLabels(t *testing.T) {
func TestWriteStorageApplyConfigsIdempotent(t *testing.T) { func TestWriteStorageApplyConfigsIdempotent(t *testing.T) {
dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsIdempotent") dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsIdempotent")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline)
@ -284,7 +296,9 @@ func TestWriteStorageApplyConfigsIdempotent(t *testing.T) {
func TestWriteStorageApplyConfigsPartialUpdate(t *testing.T) { func TestWriteStorageApplyConfigsPartialUpdate(t *testing.T) {
dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsPartialUpdate") dir, err := ioutil.TempDir("", "TestWriteStorageApplyConfigsPartialUpdate")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline) s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline)

8
tsdb/db_test.go

@ -2508,7 +2508,9 @@ func TestDBReadOnly_FlushWAL(t *testing.T) {
func TestDBCannotSeePartialCommits(t *testing.T) { func TestDBCannotSeePartialCommits(t *testing.T) {
tmpdir, _ := ioutil.TempDir("", "test") tmpdir, _ := ioutil.TempDir("", "test")
defer os.RemoveAll(tmpdir) defer func() {
testutil.Ok(t, os.RemoveAll(tmpdir))
}()
db, err := Open(tmpdir, nil, nil, nil) db, err := Open(tmpdir, nil, nil, nil)
testutil.Ok(t, err) testutil.Ok(t, err)
@ -2575,7 +2577,9 @@ func TestDBCannotSeePartialCommits(t *testing.T) {
func TestDBQueryDoesntSeeAppendsAfterCreation(t *testing.T) { func TestDBQueryDoesntSeeAppendsAfterCreation(t *testing.T) {
tmpdir, _ := ioutil.TempDir("", "test") tmpdir, _ := ioutil.TempDir("", "test")
defer os.RemoveAll(tmpdir) defer func() {
testutil.Ok(t, os.RemoveAll(tmpdir))
}()
db, err := Open(tmpdir, nil, nil, nil) db, err := Open(tmpdir, nil, nil, nil)
testutil.Ok(t, err) testutil.Ok(t, err)

39
tsdb/wal/watcher_test.go

@ -100,7 +100,9 @@ func TestTailSamples(t *testing.T) {
dir, err := ioutil.TempDir("", "readCheckpoint") dir, err := ioutil.TempDir("", "readCheckpoint")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) err = os.Mkdir(wdir, 0777)
@ -109,6 +111,9 @@ func TestTailSamples(t *testing.T) {
enc := record.Encoder{} enc := record.Encoder{}
w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) w, err := NewSize(nil, nil, wdir, 128*pageSize, compress)
testutil.Ok(t, err) testutil.Ok(t, err)
defer func() {
testutil.Ok(t, w.Close())
}()
// Write to the initial segment then checkpoint. // Write to the initial segment then checkpoint.
for i := 0; i < seriesCount; i++ { 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) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) {
dir, err := ioutil.TempDir("", "readToEnd_noCheckpoint") dir, err := ioutil.TempDir("", "readToEnd_noCheckpoint")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) err = os.Mkdir(wdir, 0777)
testutil.Ok(t, err) testutil.Ok(t, err)
w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) w, err := NewSize(nil, nil, wdir, 128*pageSize, compress)
testutil.Ok(t, err) testutil.Ok(t, err)
defer func() {
testutil.Ok(t, w.Close())
}()
var recs [][]byte var recs [][]byte
@ -242,7 +252,9 @@ func TestReadToEndWithCheckpoint(t *testing.T) {
t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) {
dir, err := ioutil.TempDir("", "readToEnd_withCheckpoint") dir, err := ioutil.TempDir("", "readToEnd_withCheckpoint")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) err = os.Mkdir(wdir, 0777)
@ -251,6 +263,9 @@ func TestReadToEndWithCheckpoint(t *testing.T) {
enc := record.Encoder{} enc := record.Encoder{}
w, err := NewSize(nil, nil, wdir, segmentSize, compress) w, err := NewSize(nil, nil, wdir, segmentSize, compress)
testutil.Ok(t, err) testutil.Ok(t, err)
defer func() {
testutil.Ok(t, w.Close())
}()
// Write to the initial segment then checkpoint. // Write to the initial segment then checkpoint.
for i := 0; i < seriesCount; i++ { 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) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) {
dir, err := ioutil.TempDir("", "readCheckpoint") dir, err := ioutil.TempDir("", "readCheckpoint")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) err = os.Mkdir(wdir, 0777)
@ -337,6 +354,9 @@ func TestReadCheckpoint(t *testing.T) {
enc := record.Encoder{} enc := record.Encoder{}
w, err := NewSize(nil, nil, wdir, 128*pageSize, compress) w, err := NewSize(nil, nil, wdir, 128*pageSize, compress)
testutil.Ok(t, err) testutil.Ok(t, err)
defer func() {
testutil.Ok(t, w.Close())
}()
// Write to the initial segment then checkpoint. // Write to the initial segment then checkpoint.
for i := 0; i < seriesCount; i++ { 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) { t.Run(fmt.Sprintf("compress=%t", compress), func(t *testing.T) {
dir, err := ioutil.TempDir("", "readCheckpoint") dir, err := ioutil.TempDir("", "readCheckpoint")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) 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) { t.Run(fmt.Sprintf("compress=%t", tc.compress), func(t *testing.T) {
dir, err := ioutil.TempDir("", "seriesReset") dir, err := ioutil.TempDir("", "seriesReset")
testutil.Ok(t, err) testutil.Ok(t, err)
defer os.RemoveAll(dir) defer func() {
testutil.Ok(t, os.RemoveAll(dir))
}()
wdir := path.Join(dir, "wal") wdir := path.Join(dir, "wal")
err = os.Mkdir(wdir, 0777) err = os.Mkdir(wdir, 0777)
@ -482,6 +506,9 @@ func TestCheckpointSeriesReset(t *testing.T) {
enc := record.Encoder{} enc := record.Encoder{}
w, err := NewSize(nil, nil, wdir, segmentSize, tc.compress) w, err := NewSize(nil, nil, wdir, segmentSize, tc.compress)
testutil.Ok(t, err) testutil.Ok(t, err)
defer func() {
testutil.Ok(t, w.Close())
}()
// Write to the initial segment, then checkpoint later. // Write to the initial segment, then checkpoint later.
for i := 0; i < seriesCount; i++ { for i := 0; i < seriesCount; i++ {

Loading…
Cancel
Save