Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
internal/stack/ | H | 21-Jul-2020 | - | |||
.gitignore | H A D | 21-Jul-2020 | 46 | |||
.travis.yml | H A D | 21-Jul-2020 | 336 | |||
CHANGELOG.md | H A D | 21-Jul-2020 | 775 | |||
LICENSE | H A D | 21-Jul-2020 | 1.1 KiB | |||
Makefile | H A D | 21-Jul-2020 | 905 | |||
README.md | H A D | 21-Jul-2020 | 2 KiB | |||
doc.go | H A D | 21-Jul-2020 | 1.2 KiB | |||
glide.yaml | H A D | 21-Jul-2020 | 146 | |||
go.mod | H A D | 21-Jul-2020 | 312 | |||
go.sum | H A D | 21-Jul-2020 | 2.8 KiB | |||
leaks.go | H A D | 21-Jul-2020 | 2.5 KiB | |||
leaks_test.go | H A D | 21-Jul-2020 | 4.5 KiB | |||
options.go | H A D | 21-Jul-2020 | 4.9 KiB | |||
options_test.go | H A D | 21-Jul-2020 | 2.7 KiB | |||
signal_test.go | H A D | 21-Jul-2020 | 1.8 KiB | |||
testmain.go | H A D | 21-Jul-2020 | 2.1 KiB | |||
testmain_test.go | H A D | 21-Jul-2020 | 2.4 KiB | |||
tools.go | H A D | 21-Jul-2020 | 1.2 KiB | |||
utils_test.go | H A D | 21-Jul-2020 | 2.3 KiB |
README.md
1# goleak [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] 2 3Goroutine leak detector to help avoid Goroutine leaks. 4 5## Installation 6 7You can use `go get` to get the latest version: 8 9`go get -u go.uber.org/goleak` 10 11`goleak` also supports semver releases. It is compatible with Go 1.5+. 12 13## Quick Start 14 15To verify that there are no unexpected goroutines running at the end of a test: 16 17```go 18func TestA(t *testing.T) { 19 defer goleak.VerifyNone(t) 20 21 // test logic here. 22} 23``` 24 25Instead of checking for leaks at the end of every test, `goleak` can also be run 26at the end of every test package by creating a `TestMain` function for your 27package: 28 29```go 30func TestMain(m *testing.M) { 31 goleak.VerifyTestMain(m) 32} 33``` 34 35## Determine Source of Package Leaks 36 37When verifying leaks using `TestMain`, the leak test is only run once after all tests 38have been run. This is typically enough to ensure there's no goroutines leaked from 39tests, but when there are leaks, it's hard to determine which test is causing them. 40 41You can use the following bash script to determine the source of the failing test: 42 43```sh 44# Create a test binary which will be used to run each test individually 45$ go test -c -o tests 46 47# Run each test individually, printing "." for successful tests, or the test name 48# for failing tests. 49$ for test in $(go test -list . | grep -E "^(Test|Example)"); do ./tests -test.run "^$test\$" &>/dev/null && echo -n "." || echo "\n$test failed"; done 50``` 51 52This will only print names of failing tests which can be investigated individually. E.g., 53 54``` 55..... 56TestLeakyTest failed 57....... 58``` 59 60## Stability 61 62goleak is v1 and follows [SemVer](http://semver.org/) strictly. 63 64No breaking changes will be made to exported APIs before 2.0. 65 66[doc-img]: https://godoc.org/go.uber.org/goleak?status.svg 67[doc]: https://godoc.org/go.uber.org/goleak 68[ci-img]: https://travis-ci.com/uber-go/goleak.svg?branch=master 69[ci]: https://travis-ci.com/uber-go/goleak 70[cov-img]: https://codecov.io/gh/uber-go/goleak/branch/master/graph/badge.svg 71[cov]: https://codecov.io/gh/uber-go/goleak 72