leak

package
v0.0.0-...-edf464d Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

leak checks for goroutine leaks in tests This is (heavily) inspired by https://github.com/grpc/grpc-go/blob/master/internal/leakcheck/leakcheck.go and https://github.com/fortytw2/leaktest

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t TestingTB)

Check adds a check to a test to ensure there are no leaked goroutines To use, simply call leak.Check(t) at the start of a test; Do not call it in defer. It is recommended to call this as the first step, as Cleanup is called in LIFO order; this ensures any Cleanup's called in the test happen first. Any existing goroutines before the test starts are filtered out. This ensures a single test failing doesn't cause all future tests to fail. However, it is still possible another test influences the result when t.Parallel is used. Where possible, CheckMain is preferred.

func CheckMain

func CheckMain(m TestingM)

CheckMain asserts that no goroutines are leaked after a test package exits. This can be used with the following code:

func TestMain(m *testing.M) {
    leak.CheckMain(m)
}

Failures here are scoped to the package, not a specific test. To determine the source of the failure, you can use the tool `go test -exec $PWD/tools/go-ordered-test ./my/package`. This runs each test individually. If there are some tests that are leaky, you the Check method can be used on individual tests.

func MustGarbageCollect

func MustGarbageCollect(tb test.Failer, i any)

MustGarbageCollect asserts that an object was garbage collected by the end of the test. The input must be a pointer to an object.

Types

type TestingM

type TestingM interface {
	Run() int
}

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

type TestingTB

type TestingTB interface {
	Cleanup(func())
	Errorf(format string, args ...any)
}

Jump to

Keyboard shortcuts

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