Browse Source

Adding small test update for temp dir using t.TempDir (#13293)

* Adding small test update for temp dir using t.TempDir

Signed-off-by: Mile Druzijanic <miledruz@gmail.com>
Signed-off-by: Mile Druzijanic <zedsprogramms@gmail.com>

* removing not required cleanup

Signed-off-by: Mile Druzijanic <zedsprogramms@gmail.com>

---------

Signed-off-by: Mile Druzijanic <miledruz@gmail.com>
Signed-off-by: Mile Druzijanic <zedsprogramms@gmail.com>
pull/13341/head^2
Mile Druzijanic 11 months ago committed by GitHub
parent
commit
2ddb3596ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      promql/engine_test.go
  2. 10
      tsdb/tsdbutil/dir_locker_testutil.go

5
promql/engine_test.go

@ -18,7 +18,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"math" "math"
"os"
"sort" "sort"
"testing" "testing"
"time" "time"
@ -47,9 +46,7 @@ func TestMain(m *testing.M) {
func TestQueryConcurrency(t *testing.T) { func TestQueryConcurrency(t *testing.T) {
maxConcurrency := 10 maxConcurrency := 10
dir, err := os.MkdirTemp("", "test_concurrency") dir := t.TempDir()
require.NoError(t, err)
defer os.RemoveAll(dir)
queryTracker := NewActiveQueryTracker(dir, maxConcurrency, nil) queryTracker := NewActiveQueryTracker(dir, maxConcurrency, nil)
t.Cleanup(queryTracker.Close) t.Cleanup(queryTracker.Close)

10
tsdb/tsdbutil/dir_locker_testutil.go

@ -60,12 +60,8 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat
for _, c := range cases { for _, c := range cases {
t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) { t.Run(fmt.Sprintf("%+v", c), func(t *testing.T) {
tmpdir, err := os.MkdirTemp("", "test") tmpdir := t.TempDir()
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, os.RemoveAll(tmpdir))
})
// Test preconditions (file already exists + lockfile option) // Test preconditions (file already exists + lockfile option)
if c.fileAlreadyExists { if c.fileAlreadyExists {
tmpLocker, err := NewDirLocker(tmpdir, "tsdb", log.NewNopLogger(), nil) tmpLocker, err := NewDirLocker(tmpdir, "tsdb", log.NewNopLogger(), nil)
@ -82,7 +78,7 @@ func TestDirLockerUsage(t *testing.T, open func(t *testing.T, data string, creat
// Check that the lockfile is always deleted // Check that the lockfile is always deleted
if !c.lockFileDisabled { if !c.lockFileDisabled {
_, err = os.Stat(locker.path) _, err := os.Stat(locker.path)
require.True(t, os.IsNotExist(err), "lockfile was not deleted") require.True(t, os.IsNotExist(err), "lockfile was not deleted")
} }
}) })

Loading…
Cancel
Save