goleak

Goroutine 泄漏检测器。「Goroutine leak detector」

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. 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 "^Test"); 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.

主要指標

概覽
名稱與所有者uber-go/goleak
主編程語言Go
編程語言Go (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2017-11-02 23:39:06
推送於2024-11-21 20:38:38
最后一次提交2024-11-21 12:38:38
發布數9
最新版本名稱v1.3.0 (發布於 )
第一版名稱v0.10.0 (發布於 2017-12-07 16:24:16)
用户参与
星數4.8k
關注者數45
派生數155
提交數85
已啟用問題?
問題數35
打開的問題數11
拉請求數79
打開的拉請求數5
關閉的拉請求數14
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?