From 812835795693bd6202a5c19d5f37724e69e204b2 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Mon, 1 Feb 2021 10:48:32 +0000 Subject: [PATCH] snapshots: fix flaky tests (#8475) The use testing.T.TempDir() seems to cause test failures in CI environvements in those cases where temporary directories' subdirs are created with permissions that are different from the defaults used by testing.T.TempDir(). The snapshots package's tests seem to be heavily affected, thus this replaces testing.T.TempDir() occurrences with ioutil.TempDir() calls. Related upstream issue: - https://github.com/golang/go/issues/40853 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- snapshots/helpers_test.go | 6 +++++- snapshots/store_test.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/snapshots/helpers_test.go b/snapshots/helpers_test.go index 5dbdd31753..751ac212d3 100644 --- a/snapshots/helpers_test.go +++ b/snapshots/helpers_test.go @@ -6,6 +6,7 @@ import ( "errors" "io" "io/ioutil" + "os" "testing" "time" @@ -100,7 +101,10 @@ func (m *mockSnapshotter) Snapshot(height uint64, format uint32) (<-chan io.Read // setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1. // The snapshot will complete when the returned closer is called. func setupBusyManager(t *testing.T) *snapshots.Manager { - tempdir := t.TempDir() + tempdir, err := ioutil.TempDir("", "") + require.NoError(t, err) + t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) + store, err := snapshots.NewStore(db.NewMemDB(), tempdir) require.NoError(t, err) hung := newHungSnapshotter() diff --git a/snapshots/store_test.go b/snapshots/store_test.go index 1a04a393c1..325fd3410b 100644 --- a/snapshots/store_test.go +++ b/snapshots/store_test.go @@ -5,6 +5,7 @@ import ( "errors" "io" "io/ioutil" + "os" "path/filepath" "testing" "time" @@ -19,7 +20,10 @@ import ( ) func setupStore(t *testing.T) *snapshots.Store { - tempdir := t.TempDir() + tempdir, err := ioutil.TempDir("", "") + require.NoError(t, err) + t.Cleanup(func() { _ = os.RemoveAll(tempdir) }) + store, err := snapshots.NewStore(db.NewMemDB(), tempdir) require.NoError(t, err)