Documentation ¶
Overview ¶
leak checks for goroutine leaks in tests This is (heavily) inspired by https://github.com/grpc/grpc-go/blob/master/internal/leakcheck/leakcheck.go and https://github.com/fortytw2/leaktest
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(t TestingTB)
Check adds a check to a test to ensure there are no leaked goroutines To use, simply call leak.Check(t) at the start of a test; Do not call it in defer. It is recommended to call this as the first step, as Cleanup is called in LIFO order; this ensures any Cleanup's called in the test happen first. Any existing goroutines before the test starts are filtered out. This ensures a single test failing doesn't cause all future tests to fail. However, it is still possible another test influences the result when t.Parallel is used. Where possible, CheckMain is preferred.
func CheckMain ¶
func CheckMain(m TestingM)
CheckMain asserts that no goroutines are leaked after a test package exits. This can be used with the following code:
func TestMain(m *testing.M) { leak.CheckMain(m) }
Failures here are scoped to the package, not a specific test. To determine the source of the failure, you can use the tool `go test -exec $PWD/tools/go-ordered-test ./my/package`. This runs each test individually. If there are some tests that are leaky, you the Check method can be used on individual tests.
func MustGarbageCollect ¶
MustGarbageCollect asserts that an object was garbage collected by the end of the test. The input must be a pointer to an object.