MyGit

uber-go/goleak

Fork: 176 Star: 3902 (更新于 1970-01-01 00:00:00)

license: MIT

Language: Go .

Goroutine leak detector

最后发布版本: v1.3.0 ( 2023-10-25 00:29:11)

GitHub网址

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.

Note that go-leak only supports the two most recent minor versions of Go.

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 -e "\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.

最近版本更新:(数据更新于 1970-01-01 00:00:00)

2023-10-25 00:29:11 v1.3.0

2023-02-14 04:13:07 v1.2.1

2022-09-08 00:09:57 v1.2.0

2021-10-05 06:18:33 v1.1.12

2021-09-09 07:28:50 v1.1.11

2020-07-22 02:43:45 v1.1.10

2020-01-08 07:13:29 v1.0.0

uber-go/goleak同语言 Go最近更新仓库

2024-12-22 07:52:58 navidrome/navidrome

2024-12-21 20:15:12 SagerNet/sing-box

2024-12-21 03:25:54 SpecterOps/BloodHound

2024-12-19 23:11:24 shadow1ng/fscan

2024-12-19 21:50:56 minio/minio

2024-12-19 10:04:39 istio/istio