Discover Packages
github.com/AlexanderYastrebov/noleak
package
module
Version:
v0.0.0-...-345842f
Opens a new window with list of versions in this module.
Published: Jul 11, 2023
License: BSD-3-Clause
Opens a new window with license information.
Imports: 7
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Simple goroutine leak detector
It compares the list of active goroutines before and after the test and reports an error on mismatch.
To enable detector add a main_test.go file to the package.
To check a specific test only add noleak.Check(t)
at the top .
Tests using http.Client or http.DefaultClient should close idle connections .
See and run all examples :
GODEBUG=tracebackancestors=10 go test ./examples/...
Setting GODEBUG=tracebackancestors=N
extends tracebacks with the stacks at
which goroutines were created, where N limits the number of ancestor goroutines to
report, see https://pkg.go.dev/runtime#hdr-Environment_Variables .
Credits
Expand ▾
Collapse ▴
Documentation
¶
Check reports test error if there are active goroutines after test ends.
Example:
func TestLeak(t *testing.T) {
noleak.Check(t)
...
}
CheckMain prints active goroutines after all tests end.
It returns result of m.Run() or non-zero if there are active goroutines.
Example:
func TestMain(m *testing.M) {
os.Exit(noleak.CheckMain(m))
}
func CheckMainFunc(m func() int ) (code int )
CheckMainFunc prints active goroutines after m ends.
It returns result of m or non-zero if there are active goroutines.
Example:
func TestMain(m *testing.M) {
os.Exit(noleak.CheckMainFunc(func() int {
code := m.Run()
// perform cleanup
...
return code
}))
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.