Documentation
¶
Overview ¶
Package goleak is a Goroutine leak detector.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyNone ¶
VerifyNone marks the given TestingT as failed if any extra goroutines are found by Find. This is a helper method to make it easier to integrate in tests by doing:
defer VerifyNone(t)
VerifyNone is currently incompatible with t.Parallel because it cannot associate specific goroutines with specific tests. Thus, non-leaking goroutines from other tests running in parallel could fail this check. If you need to run tests in parallel, use VerifyTestMain instead, which will verify that no leaking goroutines exist after ALL tests finish.
func VerifyTestMain ¶
VerifyTestMain can be used in a TestMain function for package tests to verify that there were no goroutine leaks. To use it, your TestMain function should look like:
func TestMain(m *testing.M) { goleak.VerifyTestMain(m) }
See https://golang.org/pkg/testing/#hdr-Main for more details.
This will run all tests as per normal, and if they were successful, look for any goroutine leaks and fail the tests if any leaks were found.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option lets users specify custom verifications.
func Cleanup ¶ added in v1.2.0
Cleanup sets up a cleanup function that will be executed at the end of the leak check. When passed to VerifyTestMain, the exit code passed to cleanupFunc will be set to the exit code of TestMain. When passed to VerifyNone, the exit code will be set to 0. This cannot be passed to Find.
func IgnoreAnyFunction ¶ added in v1.3.0
IgnoreAnyFunction ignores goroutines where the specified function is present anywhere in the stack.
The function name must be fully qualified, e.g.,
go.uber.org/goleak.IgnoreAnyFunction
For methods, the fully qualified form looks like:
go.uber.org/goleak.(*MyType).MyMethod
func IgnoreCurrent ¶ added in v1.1.0
func IgnoreCurrent() Option
IgnoreCurrent records all current goroutines when the option is created, and ignores them in any future Find/Verify calls.
func IgnoreTopFunction ¶
IgnoreTopFunction ignores any goroutines where the specified function is at the top of the stack. The function name should be fully qualified, e.g., go.uber.org/goleak.IgnoreTopFunction