Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Enable goleak for cli tests #3370

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

Merged
merged 6 commits into from
Aug 12, 2022
Merged
Changes from 1 commit
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
Next Next commit
fix: Enable goleak for cli tests
  • Loading branch information
mafredri committed Aug 3, 2022
commit 029f1af93642b18673f56083d9c8dccee03440a9
12 changes: 8 additions & 4 deletions cli/root_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cli

import (
"os"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func Test_formatExamples(t *testing.T) {
Expand Down Expand Up @@ -67,7 +67,11 @@ func Test_formatExamples(t *testing.T) {
}

func TestMain(m *testing.M) {
// Replace with goleak.VerifyTestMain(m) when we enable goleak.
os.Exit(m.Run())
// goleak.VerifyTestMain(m)
goleak.VerifyTestMain(m,
// The lumberjack library is used by by agent and seems to leave
// goroutines after Close(), fails TestGitSSH tests.
// https://github.com/natefinch/lumberjack/pull/100
Copy link
Member

Choose a reason for hiding this comment

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

Should we do a go mod replace instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I haven't done a proper review of that PR, and I'm not confident in using it in a production environment without doing so. My judgement was that this is a non-issue in a production environment since the agent only runs once and thus won't be leaking memory, so I think the goleak ignore is acceptable here.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense! TY sir

goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).mill.func1"),
)
}