• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

internal/stack/H21-Jul-2020-

.gitignoreH A D21-Jul-202046

.travis.ymlH A D21-Jul-2020336

CHANGELOG.mdH A D21-Jul-2020775

LICENSEH A D21-Jul-20201.1 KiB

MakefileH A D21-Jul-2020905

README.mdH A D21-Jul-20202 KiB

doc.goH A D21-Jul-20201.2 KiB

glide.yamlH A D21-Jul-2020146

go.modH A D21-Jul-2020312

go.sumH A D21-Jul-20202.8 KiB

leaks.goH A D21-Jul-20202.5 KiB

leaks_test.goH A D21-Jul-20204.5 KiB

options.goH A D21-Jul-20204.9 KiB

options_test.goH A D21-Jul-20202.7 KiB

signal_test.goH A D21-Jul-20201.8 KiB

testmain.goH A D21-Jul-20202.1 KiB

testmain_test.goH A D21-Jul-20202.4 KiB

tools.goH A D21-Jul-20201.2 KiB

utils_test.goH A D21-Jul-20202.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