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 ¶
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 ¶
Command is exec.Command bound to t. Add to cmd.Env rather than replacing it, so the helper keeps its deadline.
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.
Types ¶
This section is empty.