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

Global way to ignore known leaks from a set of tests #54

Open
prashantv opened this issue Apr 20, 2021 · 1 comment
Open

Global way to ignore known leaks from a set of tests #54

prashantv opened this issue Apr 20, 2021 · 1 comment
Assignees

Comments

@prashantv
Copy link
Collaborator

Currently, every call to goleak.Verify* needs to specify any stacks to ignore. If there are known leaks which affect multiple packages, this results in duplication in each package specifying the same ignores.

We should investigate approaches to make this easier, as a strawman proposal:
Add AppendDefaultOptions as an exported function that allows appending a default set of ignores, that can be called in some init function, and can be shared for all tests by depending on the package that adds the default options.

@sywhang sywhang self-assigned this Jan 10, 2023
@abhinav
Copy link
Collaborator

abhinav commented Nov 10, 2023

Things have changed since the original strawman proposal: there's a Cleanup option, so AppendDefaultOptions might not be what we want.

We could do something like AppendKnownLeaks instead. It'll still take an Option, but panic if Cleanup is specified. And with global registration, we may want the ability to reverse the append even if we're not likely to use it.

func AppendKnownLeaks(opts ...Option) (undo func())

That said, I'm not sure this or the original proposal will be sufficient.

Known leaks need to be ignored in all tests of a module. Tests for each package in the module run as separate binaries.
So every test package will have to remember to import _ "example.com/internal/knownleaks" to get the global leaks registered. That's not too far removed from writing an internal wrapper around goleak (import "example.com/internal/goleak") that just passes known leaks to VerifyTestMain as needed.
Do you think the global list of ignores would still be worth it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants