Help us shape the future of Go! Take the 2026 Go Developer Survey

leakcheck

package
v0.1.160 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package leakcheck provides test-time helpers for detecting resource leaks: file descriptors, docker containers, and (via go.uber.org/goleak wired at the TestMain level) goroutines.

Usage in a test:

func TestSomething(t *testing.T) {
    defer leakcheck.FDCheck(t)()
    // test body
}

The returned closure records the baseline and, when deferred, compares to the current count. A small slack (2 by default) accommodates buffered log writes and is configurable via FDCheckN.

DockerContainerCheck compares the count of containers matching a label filter before/after the test, catching runaway container leaks from docker-based runners.

All functions are safe no-ops on platforms where the underlying probe is unavailable; they log a diagnostic rather than failing the test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerContainerCheck

func DockerContainerCheck(t testing.TB, filter string) func()

DockerContainerCheck returns a deferred checker that verifies no new containers matching filter are left running by the test. filter is a docker ps --filter expression, e.g. "label=test-codefly=true" or "name=codefly-test-".

If docker is unavailable, the check is skipped with a log line.

func FDCheck

func FDCheck(t testing.TB) func()

FDCheck returns a deferred-style checker that records the current FD count and, on invocation, fails the test if more than 2 additional FDs are open. Equivalent to FDCheckN(t, 2).

func FDCheckN

func FDCheckN(t testing.TB, slack int) func()

FDCheckN is FDCheck with a configurable slack.

Types

This section is empty.

Jump to

Keyboard shortcuts

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