prometheus/vendor/go.uber.org/goleak
Julien Pivotto d668a7efe3
Update go dependencies (#7837)
Update dependencies before 2.21 release

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-08-24 14:03:47 +02:00
..
internal/stack tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
.gitignore tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
.travis.yml Update go dependencies (#7837) 2020-08-24 14:03:47 +02:00
CHANGELOG.md Update go dependencies (#7837) 2020-08-24 14:03:47 +02:00
doc.go tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
glide.yaml tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
go.mod tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
go.sum tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
leaks.go tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
LICENSE tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
Makefile tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
options.go Update go dependencies (#7837) 2020-08-24 14:03:47 +02:00
README.md Update go dependencies (#7837) 2020-08-24 14:03:47 +02:00
testmain.go tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00
tools.go tsdb: test for leaks (#7566) 2020-07-21 10:08:06 +02:00

goleak GoDoc Build Status Coverage Status

Goroutine leak detector to help avoid Goroutine leaks.

Installation

You can use go get to get the latest version:

go get -u go.uber.org/goleak

goleak also supports semver releases. It is compatible with Go 1.5+.

Quick Start

To verify that there are no unexpected goroutines running at the end of a test:

func TestA(t *testing.T) {
	defer goleak.VerifyNone(t)

	// test logic here.
}

Instead of checking for leaks at the end of every test, goleak can also be run at the end of every test package by creating a TestMain function for your package:

func TestMain(m *testing.M) {
	goleak.VerifyTestMain(m)
}

Determine Source of Package Leaks

When verifying leaks using TestMain, the leak test is only run once after all tests have been run. This is typically enough to ensure there's no goroutines leaked from tests, but when there are leaks, it's hard to determine which test is causing them.

You can use the following bash script to determine the source of the failing test:

# Create a test binary which will be used to run each test individually
$ go test -c -o tests

# Run each test individually, printing "." for successful tests, or the test name
# for failing tests.
$ for test in $(go test -list . | grep -E "^(Test|Example)"); do ./tests -test.run "^$test\$" &>/dev/null && echo -n "." || echo "\n$test failed"; done

This will only print names of failing tests which can be investigated individually. E.g.,

.....
TestLeakyTest failed
.......

Stability

goleak is v1 and follows SemVer strictly.

No breaking changes will be made to exported APIs before 2.0.