MCPcopy
hub / github.com/uber-go/goleak / VerifyTestMain

Function VerifyTestMain

testmain.go:52–69  ·  view source on GitHub ↗

VerifyTestMain can be used in a TestMain function for package tests to verify that there were no goroutine leaks. To use it, your TestMain function should look like: func TestMain(m *testing.M) { goleak.VerifyTestMain(m) } See https://golang.org/pkg/testing/#hdr-Main for more details. This w

(m TestingM, options ...Option)

Source from the content-addressed store, hash-verified

50// This will run all tests as per normal, and if they were successful, look
51// for any goroutine leaks and fail the tests if any leaks were found.
52func VerifyTestMain(m TestingM, options ...Option) {
53 exitCode := m.Run()
54 opts := buildOpts(options...)
55
56 var cleanup func(int)
57 cleanup, opts.cleanup = opts.cleanup, nil
58 if cleanup == nil {
59 cleanup = _osExit
60 }
61 defer func() { cleanup(exitCode) }()
62
63 if exitCode == 0 {
64 if err := Find(opts); err != nil {
65 fmt.Fprintf(_osStderr, "goleak: Errors on successful test run: %v\n", err)
66 exitCode = 1
67 }
68 }
69}

Callers 1

TestVerifyTestMainFunction · 0.85

Calls 3

buildOptsFunction · 0.85
FindFunction · 0.85
RunMethod · 0.65

Tested by 1

TestVerifyTestMainFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…