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

[backport/v0.41.x]: snapshots: fix flaky tests #8484

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion snapshots/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -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) })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this works, and t.TempDir doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at how testing.T.TempDir() is implemented. Plus, please read the original commit's comment. It's quite a common issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks. Maybe we should add a comment to the code explaining shortly why we use ioutil.TempDir or link the golang issue?

Copy link
Contributor Author

@alessio alessio Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about it. Then I thought that git blame & git log could provide enough documentation. But you're right, an inline comment would be definitely more helpful and convenient. I'll fix it in a PR to master

Copy link
Collaborator

@robert-zaremba robert-zaremba Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - let's update. thanks. It takes way more energy to do git blame; git log than adding a comment. Also, it's much easier to read that comment then think about this workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


store, err := snapshots.NewStore(db.NewMemDB(), tempdir)
require.NoError(t, err)
hung := newHungSnapshotter()
Expand Down
6 changes: 5 additions & 1 deletion snapshots/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
Expand All @@ -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)

Expand Down