goleak

package module
v0.10.1-0...-db282e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 6 Imported by: 0

README

goleak GoDoc Build Status Coverage Status

Goroutine leak detector to help avoid Goroutine leaks.

Development Status: Alpha

goleak is still in development, and APIs are still in flux.

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.VerifyNoLeaks(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)
}

Documentation

Overview

Package goleak is a Goroutine leak detector.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindLeaks

func FindLeaks(options ...Option) error

FindLeaks looks for extra goroutines, and returns a descriptive error if any are found.

func VerifyNoLeaks

func VerifyNoLeaks(t TestingT, options ...Option)

VerifyNoLeaks calls FindLeaks and calls Error on the passed in TestingT if any leaks are found. This is a helper method to make it easier to integrate in tests by doing: defer VerifyNoLeaks(t)

func VerifyTestMain

func VerifyTestMain(m TestingM, options ...Option)

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)
}

This will run all tests as per normal, and if they were successful, look for any goroutine leaks and fail the tests if any leaks were found.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option lets users specify custom verifications.

func IgnoreTopFunction

func IgnoreTopFunction(f string) Option

IgnoreTopFunction ignores any goroutines where the specified function is at the top of the stack. The function name should be fully qualified, e.g., go.uber.org/goleak.IgnoreTopFunction

type TestingM

type TestingM interface {
	Run() int
}

TestingM is the minimal subset of testing.M that we use.

type TestingT

type TestingT interface {
	Error(...interface{})
}

TestingT is the minimal subset of testing.TB that we use.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL