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)
| 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. |
| 52 | func 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 | } |
searching dependent graphs…