proctest

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proctest keeps the processes tests start from outliving them.

  • Command (test side) ties a child to the test: it is killed, with its process group, when the test ends or its deadline passes, and it gets that deadline in EnvDeadline.
  • Guard (child side) is a helper's first call: the helper exits at the deadline, or as soon as the process that started it is gone, even when the test binary was killed and no cleanup ran.
  • Main (package side) kills any child still running shortly before -test.timeout and after the tests.

-test.timeout alone is not enough: helpers dispatched from TestMain never arm it, -test.run helpers are started without it, and a child stuck between fork and exec runs no Go code at all (seen with -race on macOS: the fork child spins in the race runtime with signals blocked).

Index

Constants

View Source
const (
	// EnvDeadline carries a helper's deadline (Unix nanoseconds).
	EnvDeadline = "DMG_PROCTEST_DEADLINE"
	// DefaultTimeout bounds a helper started without a deadline.
	DefaultTimeout = 10 * time.Minute
	// ExitGuard is a helper's exit code when Guard ends it.
	ExitGuard = 86
)

Variables

This section is empty.

Functions

func Command

func Command(t testing.TB, name string, args ...string) *exec.Cmd

Command is exec.Command bound to t. Add to cmd.Env rather than replacing it, so the helper keeps its deadline.

func Guard

func Guard()

Guard ends this helper process at its deadline or when its parent exits.

func GuardDeadline

func GuardDeadline()

GuardDeadline is Guard without the parent watch, for helpers whose test checks that something else kills them once their parent is gone.

func KillChildren

func KillChildren() int

KillChildren kills every live child of this process (and, on Unix, its process group) and returns how many it found.

func KillPid

func KillPid(pid int)

KillPid kills pid and, on Unix, the process group it leads.

func Main

func Main(m *testing.M) int

Main runs the tests for TestMain, killing children still running shortly before -test.timeout (failing the run) and after the tests.

func WaitGone

func WaitGone(pid int, d time.Duration) bool

WaitGone reports whether pid (not a child of this process) exits within d.

Types

This section is empty.

Jump to

Keyboard shortcuts

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