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

Allow checking for functions anywhere in the stack #80

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ func Cleanup(cleanupFunc func(exitCode int)) Option {
})
}

// IgnoreAnyFunction ignores any goroutines where the specified function
// is anywhere in the stack. The function name should be fully qualified,
// e.g., go.uber.org/goleak.IgnoreTopFunction
func IgnoreAnyFunction(f string) Option {
return addFilter(func(s stack.Stack) bool {
return strings.Contains(s.Full(), f)
})
}

// IgnoreCurrent records all current goroutines when the option is created, and ignores
// them in any future Find/Verify calls.
func IgnoreCurrent() Option {
Expand Down
4 changes: 4 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestOptionsFilters(t *testing.T) {
// If we add an extra filter to ignore blockTill, it shouldn't match.
opts = buildOpts(IgnoreTopFunction("go.uber.org/goleak.(*blockedG).run"))
require.Zero(t, countUnfiltered(), "blockedG should be filtered out. running: %v", stack.All())

// If we add an extra filter to ignore startBlockedG (second item in the stack), it shouldn't match.
opts = buildOpts(IgnoreAnyFunction("go.uber.org/goleak.startBlockedG"))
require.Zero(t, countUnfiltered(), "startBlockedG should be filtered out. running: %v", stack.All())
}

func TestOptionsRetry(t *testing.T) {
Expand Down