Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-release-notes] Change some tests to use t.TempDir instead of os.TempDir so that their temporary files get cleaned up. #8792

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
41fe1ac
[no-release-notes] Change some tests to use t.TempDir instead of os.T…
reltuk Jan 25, 2025
742f276
go/cmd/dolt: signed_commits_test.go: Try to close DoltDBs so that win…
reltuk Jan 28, 2025
be448ee
go/cmd/dolt: signed_commits_test.go: Try a different way to cleanup t…
reltuk Jan 28, 2025
98547ce
Bug fix: fixing ref conflict case that can cause tags to be temporari…
fulghum Jan 24, 2025
2e8fded
Fixing a merge error that included the env section twice
fulghum Jan 24, 2025
f9affcc
[ga-bump-release] Update Dolt version to 1.47.2 and release v1.47.2
coffeegoddd Jan 24, 2025
bd8c834
[ga-bump-dep] Bump dependency in Dolt by jycor (#8790)
coffeegoddd Jan 27, 2025
cce2336
Add the dirty column to the dolt_branches system table
macneale4 Jan 27, 2025
ecea68c
Tests for the dolt_branches dirty column
macneale4 Jan 27, 2025
4bda2e4
[ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/upda…
macneale4 Jan 27, 2025
ccb34c4
Fix workbench tests to expect dirty column
macneale4 Jan 27, 2025
7f7f2c6
Don't error out when no workingset is found
macneale4 Jan 27, 2025
83bbd17
[ga-bump-release] Update Dolt version to 1.48.0 and release v1.48.0
coffeegoddd Jan 28, 2025
8f25c11
go/store/nbs: store.go: Add a mechanism to bracket outstanding read r…
reltuk Jan 15, 2025
1f4b487
go/store/nbs: chunkReader,chunkSource: GC: Add the ability to take de…
reltuk Jan 15, 2025
2f47ac2
go/store/nbs: Add GC keeper calls on reads through NomsBlockStore.
reltuk Jan 16, 2025
7c06b6b
go/store/nbs: tablePersister: Add GC dependency capturing to written …
reltuk Jan 16, 2025
8a5689e
go/store/nbs: table_set: append: Thread GC dependency tracking throug…
reltuk Jan 16, 2025
f69f4a4
go/store/nbs: store.go: MarkAndSweepChunks: After adding read trackin…
reltuk Jan 16, 2025
de5c178
repofmt.sh.
reltuk Jan 16, 2025
bba09b1
go/store/nbs: store.go: Fix errgroup context usage-after-Wait bug in …
reltuk Jan 23, 2025
c2ec3de
go: binlogreplication: Add Session{{Begin,End}Command,End} lifecycle …
reltuk Jan 28, 2025
09816e3
go: cmd/dolt: sqlengine: Actually call DoltBinlogReplicaController.Cl…
reltuk Jan 28, 2025
6f6207b
[ga-bump-dep] Bump dependency in Dolt by zachmu
zachmu Jan 28, 2025
c8e47a8
go/store/nbs: generational_chunk_store.go: In GCMode_Full, also take …
reltuk Jan 28, 2025
872f8d9
/go/libraries/doltcore/env/actions: make iter resolved tags paginated…
coffeegoddd Jan 21, 2025
a80e71b
/go/libraries/doltcore/env/actions/tag.go: reinstage iterresolved tag…
coffeegoddd Jan 30, 2025
d4dd7aa
[ga-bump-dep] Bump dependency in Dolt by Hydrocharged
Hydrocharged Jan 31, 2025
72ec11f
Include deleteErr message in returned error.
fulghum Jan 31, 2025
eed637b
go: store/types: Fix dolt_gc on databases that use vector indexes.
reltuk Jan 30, 2025
d3b9e44
go: sqlserver: Clean up how remotesrv gets a handle to the mrEnv.File…
reltuk Jan 28, 2025
86acc8c
go: sqle,remotesrv: Implement sql.Session lifecycle callbacks for sql…
reltuk Jan 28, 2025
ff7aebb
Fix typo in error message.
reltuk Jan 30, 2025
29cb66e
go/cmd/dolt/commands: Declare bankruptcy on signed commit test for now.
reltuk Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions go/cmd/dolt/commands/signed_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
"github.com/dolthub/dolt/go/libraries/doltcore/env"
"github.com/dolthub/dolt/go/libraries/utils/argparser"
"github.com/dolthub/dolt/go/libraries/utils/config"
Expand All @@ -45,10 +46,9 @@ func importKey(t *testing.T, ctx context.Context) {
}

func setupTestDB(t *testing.T, ctx context.Context, fs filesys.Filesys) string {
dir, err := os.MkdirTemp(os.TempDir(), "signed_commits")
require.NoError(t, err)
dir := t.TempDir()
dbDir := filepath.Join(dir, "db")
err = filesys.CopyDir("testdata/signed_commits/db/", dbDir, fs)
err := filesys.CopyDir("testdata/signed_commits/db/", dbDir, fs)
require.NoError(t, err)

log.Println(dbDir)
Expand Down Expand Up @@ -79,6 +79,9 @@ func TestSignAndVerifyCommit(t *testing.T) {
ctx := context.Background()
importKey(t, ctx)
dbDir := setupTestDB(t, ctx, filesys.LocalFS)
t.Cleanup(func() {
dbfactory.CloseAllLocalDatabases()
})

global := map[string]string{
"user.name": "First Last",
Expand All @@ -90,7 +93,7 @@ func TestSignAndVerifyCommit(t *testing.T) {
apr, err := cli.CreateCommitArgParser().Parse(test.commitArgs)
require.NoError(t, err)

_, err = execCommand(ctx, dbDir, CommitCmd{}, test.commitArgs, apr, map[string]string{}, global)
_, err = execCommand(ctx, t, dbDir, CommitCmd{}, test.commitArgs, apr, map[string]string{}, global)

if test.expectErr {
require.Error(t, err)
Expand All @@ -103,14 +106,14 @@ func TestSignAndVerifyCommit(t *testing.T) {
apr, err = cli.CreateLogArgParser(false).Parse(args)
require.NoError(t, err)

logOutput, err := execCommand(ctx, dbDir, LogCmd{}, args, apr, map[string]string{}, global)
logOutput, err := execCommand(ctx, t, dbDir, LogCmd{}, args, apr, map[string]string{}, global)
require.NoError(t, err)
require.Contains(t, logOutput, "Good signature from \"Test User <[email protected]>\"")
})
}
}

func execCommand(ctx context.Context, wd string, cmd cli.Command, args []string, apr *argparser.ArgParseResults, local, global map[string]string) (output string, err error) {
func execCommand(ctx context.Context, t *testing.T, wd string, cmd cli.Command, args []string, apr *argparser.ArgParseResults, local, global map[string]string) (output string, err error) {
err = os.Chdir(wd)
if err != nil {
err = fmt.Errorf("error changing directory to %s: %w", wd, err)
Expand Down Expand Up @@ -157,7 +160,7 @@ func execCommand(ctx context.Context, wd string, cmd cli.Command, args []string,

initialOut := os.Stdout
initialErr := os.Stderr
f, err := os.CreateTemp(os.TempDir(), "signed-commit-test-*")
f, err := os.CreateTemp(t.TempDir(), "signed-commit-test-*")
if err != nil {
err = fmt.Errorf("error creating temp file: %w", err)
return
Expand Down
8 changes: 4 additions & 4 deletions go/libraries/doltcore/doltdb/commit_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestPushOnWriteHook(t *testing.T) {
ctx := context.Background()

// destination repo
testDir, err := test.ChangeToTestDir("TestReplicationDest")
testDir, err := test.ChangeToTestDir(t.TempDir(), "TestReplicationDest")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand All @@ -62,7 +62,7 @@ func TestPushOnWriteHook(t *testing.T) {
destDB, _ := LoadDoltDB(context.Background(), types.Format_Default, LocalDirDoltDB, filesys.LocalFS)

// source repo
testDir, err = test.ChangeToTestDir("TestReplicationSource")
testDir, err = test.ChangeToTestDir(t.TempDir(), "TestReplicationSource")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestAsyncPushOnWrite(t *testing.T) {
ctx := context.Background()

// destination repo
testDir, err := test.ChangeToTestDir("TestReplicationDest")
testDir, err := test.ChangeToTestDir(t.TempDir(), "TestReplicationDest")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand All @@ -202,7 +202,7 @@ func TestAsyncPushOnWrite(t *testing.T) {
destDB, _ := LoadDoltDB(context.Background(), types.Format_Default, LocalDirDoltDB, filesys.LocalFS)

// source repo
testDir, err = test.ChangeToTestDir("TestReplicationSource")
testDir, err = test.ChangeToTestDir(t.TempDir(), "TestReplicationSource")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand Down
6 changes: 3 additions & 3 deletions go/libraries/doltcore/doltdb/doltdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestEmptyInMemoryRepoCreation(t *testing.T) {
}

func TestLoadNonExistentLocalFSRepo(t *testing.T) {
_, err := test.ChangeToTestDir("TestLoadRepo")
_, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand All @@ -231,7 +231,7 @@ func TestLoadNonExistentLocalFSRepo(t *testing.T) {
}

func TestLoadBadLocalFSRepo(t *testing.T) {
testDir, err := test.ChangeToTestDir("TestLoadRepo")
testDir, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand All @@ -246,7 +246,7 @@ func TestLoadBadLocalFSRepo(t *testing.T) {
}

func TestLDNoms(t *testing.T) {
testDir, err := test.ChangeToTestDir("TestLoadRepo")
testDir, err := test.ChangeToTestDir(t.TempDir(), "TestLoadRepo")

if err != nil {
panic("Couldn't change the working directory to the test directory.")
Expand Down
8 changes: 1 addition & 7 deletions go/libraries/doltcore/dtestutils/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package dtestutils

import (
"context"
"os"
"path/filepath"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
Expand All @@ -41,12 +40,7 @@ func CreateTestEnv() *env.DoltEnv {
// CreateTestEnvForLocalFilesystem creates a new DoltEnv for testing, using a local FS, instead of an in-memory
// filesystem, for persisting files. This is useful for tests that require a disk-based filesystem and will not
// work correctly with an in-memory filesystem and in-memory blob store (e.g. dolt_undrop() tests).
func CreateTestEnvForLocalFilesystem() *env.DoltEnv {
tempDir, err := os.MkdirTemp(os.TempDir(), "dolt-*")
if err != nil {
panic(err)
}

func CreateTestEnvForLocalFilesystem(tempDir string) *env.DoltEnv {
fs, err := filesys.LocalFilesysWithWorkingDir(tempDir)
if err != nil {
panic(err)
Expand Down
8 changes: 2 additions & 6 deletions go/libraries/doltcore/dtestutils/sql_server_driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ type DoltUser struct {
var _ DoltCmdable = DoltUser{}
var _ DoltDebuggable = DoltUser{}

func NewDoltUser() (DoltUser, error) {
tmpdir, err := os.MkdirTemp("", "go-sql-server-driver-")
if err != nil {
return DoltUser{}, err
}
func NewDoltUser(tmpdir string) (DoltUser, error) {
res := DoltUser{tmpdir}
err = res.DoltExec("config", "--global", "--add", "metrics.disabled", "true")
err := res.DoltExec("config", "--global", "--add", "metrics.disabled", "true")
if err != nil {
return DoltUser{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions go/libraries/doltcore/env/multi_repo_env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func initRepoWithRelativePath(t *testing.T, envPath string, hdp HomeDirProvider)
}

func TestMultiEnvForDirectory(t *testing.T) {
rootPath, err := test.ChangeToTestDir("TestDoltEnvAsMultiEnv")
rootPath, err := test.ChangeToTestDir(t.TempDir(), "TestDoltEnvAsMultiEnv")
require.NoError(t, err)

hdp := func() (string, error) { return rootPath, nil }
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestMultiEnvForDirectory(t *testing.T) {
}

func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) {
rootPath, err := test.ChangeToTestDir("TestDoltEnvAsMultiEnvWithMultipleRepos")
rootPath, err := test.ChangeToTestDir(t.TempDir(), "TestDoltEnvAsMultiEnvWithMultipleRepos")
require.NoError(t, err)

hdp := func() (string, error) { return rootPath, nil }
Expand All @@ -177,7 +177,7 @@ func TestMultiEnvForDirectoryWithMultipleRepos(t *testing.T) {
}

func initMultiEnv(t *testing.T, testName string, names []string) (string, HomeDirProvider, map[string]*DoltEnv) {
rootPath, err := test.ChangeToTestDir(testName)
rootPath, err := test.ChangeToTestDir(t.TempDir(), testName)
require.NoError(t, err)

hdp := func() (string, error) { return rootPath, nil }
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func (d *DoltHarness) newProvider() sql.MutableDatabaseProvider {

var dEnv *env.DoltEnv
if d.useLocalFilesystem {
dEnv = dtestutils.CreateTestEnvForLocalFilesystem()
dEnv = dtestutils.CreateTestEnvForLocalFilesystem(d.t.TempDir())
} else {
dEnv = dtestutils.CreateTestEnv()
}
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/events/event_flush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestEventFlushing(t *testing.T) {
fs := filesys.LocalFS

path := filepath.Join(dPath, evtPath)
dDir := testLib.TestDir(path)
dDir := testLib.TestDir(t.TempDir(), path)

ft = createFlushTester(fs, "", dDir)
}
Expand Down
10 changes: 5 additions & 5 deletions go/libraries/utils/filesys/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var filesysetmsToTest = map[string]Filesys{
}

func TestFilesystems(t *testing.T) {
dir := test.TestDir("filesys_test")
newLocation := test.TestDir("newLocation")
dir := test.TestDir(t.TempDir(), "filesys_test")
newLocation := test.TestDir(t.TempDir(), "newLocation")
subdir := filepath.Join(dir, "subdir")
subdirFile := filepath.Join(subdir, testSubdirFilename)
fp := filepath.Join(dir, testFilename)
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestNewInMemFS(t *testing.T) {
}

func TestRecursiveFSIteration(t *testing.T) {
dir := test.TestDir("TestRecursiveFSIteration")
dir := test.TestDir(t.TempDir(), "TestRecursiveFSIteration")

for fsName, fs := range filesysetmsToTest {
var expectedDirs []string
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestRecursiveFSIteration(t *testing.T) {
}

func TestFSIteration(t *testing.T) {
dir := test.TestDir("TestFSIteration")
dir := test.TestDir(t.TempDir(), "TestFSIteration")

for fsName, fs := range filesysetmsToTest {
var expectedDirs []string
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestFSIteration(t *testing.T) {
}

func TestDeletes(t *testing.T) {
dir := test.TestDir("TestDeletes")
dir := test.TestDir(t.TempDir(), "TestDeletes")

for fsName, fs := range filesysetmsToTest {
var ignored []string
Expand Down
16 changes: 4 additions & 12 deletions go/libraries/utils/test/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,19 @@ import (
)

// TestDir creates a subdirectory inside the systems temp directory
func TestDir(testName string) string {
id, err := uuid.NewRandom()

if err != nil {
panic(ShouldNeverHappen)
}

return filepath.Join(os.TempDir(), testName, id.String())
func TestDir(dir, testName string) string {
return filepath.Join(dir, testName, uuid.NewString())
}

// ChangeToTestDir creates a new test directory and changes the current directory to be
func ChangeToTestDir(testName string) (string, error) {
dir := TestDir(testName)
func ChangeToTestDir(tempDir, testName string) (string, error) {
dir := TestDir(tempDir, testName)
err := os.MkdirAll(dir, os.ModePerm)

if err != nil {
return "", err
}

err = os.Chdir(dir)

if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/utils/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// test your tests so you can test while you test

func TestLDTestUtils(t *testing.T) {
dir, err := ChangeToTestDir("TestLDTestUtils")
dir, err := ChangeToTestDir(t.TempDir(), "TestLDTestUtils")

if err != nil {
t.Fatal("Couldn't change to test dir")
Expand Down
10 changes: 8 additions & 2 deletions go/performance/import_benchmarker/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ func main() {
if err != nil {
log.Fatalln(err)
}
defer os.RemoveAll(tmpdir)

userdir, err := os.MkdirTemp("", "import-benchmarker-")
if err != nil {
log.Fatalln(err)
}
defer os.RemoveAll(userdir)

results := new(ib.ImportResults)
u, err := driver.NewDoltUser()
u, err := driver.NewDoltUser(userdir)
for _, test := range def.Tests {
test.Results = results
test.InitWithTmpDir(tmpdir)
Expand Down Expand Up @@ -73,5 +80,4 @@ func main() {
} else {
fmt.Println(results.SqlDump())
}
os.Exit(0)
}
2 changes: 1 addition & 1 deletion go/performance/import_benchmarker/testdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (test *ImportTest) Run(t *testing.T) {
test.InitWithTmpDir(tmp)
}

u, err := driver.NewDoltUser()
u, err := driver.NewDoltUser(t.TempDir())
for _, r := range test.Repos {
if r.ExternalServer != nil {
err := test.RunExternalServerTests(r.Name, r.ExternalServer)
Expand Down
10 changes: 8 additions & 2 deletions go/performance/sysbench/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ func main() {
if err != nil {
log.Fatalln(err)
}
defer os.RemoveAll(tmpdir)

userdir, err := os.MkdirTemp("", "sysbench-user-dir_")
if err != nil {
log.Fatalln(err)
}
defer os.RemoveAll(userdir)

results := new(sysbench.Results)
u, err := driver.NewDoltUser()
u, err := driver.NewDoltUser(userdir)
for _, test := range defs.Tests {
test.InitWithTmpDir(tmpdir)

Expand Down Expand Up @@ -83,5 +90,4 @@ func main() {
} else {
fmt.Println(results.SqlDump())
}
os.Exit(0)
}
2 changes: 1 addition & 1 deletion go/performance/sysbench/testdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (test *Script) Run(t *testing.T) {
}

results := new(Results)
u, err := driver.NewDoltUser()
u, err := driver.NewDoltUser(t.TempDir())
test.Results = results
test.InitWithTmpDir(tmpdir)
for _, r := range test.Repos {
Expand Down
Loading
Loading