Documentation
¶
Overview ¶
Package ownedproc runs a child process with exactly one owner of its wait.
A started process has two things a test needs: a way to signal it, and a way to learn that it exited. Splitting those between a body and a teardown path invites two waiters on one child, and concurrent waits can reap the wrong process once an id is reused (go.dev/issue/67642). One goroutine therefore owns the wait for a child's whole life; everything else observes completion through Done and signals through the retained process object.
Test-support only. It lives under internal/ and is imported solely by _test.go files; nothing here is part of the product surface.
Index ¶
- Variables
- type Child
- func (c *Child) AwaitExit(timeout time.Duration) (error, bool)
- func (c *Child) Done() <-chan struct{}
- func (c *Child) Err() error
- func (c *Child) KillCalls() int64
- func (c *Child) PID() int
- func (c *Child) Signal(sig os.Signal) error
- func (c *Child) Stop(timeout time.Duration) error
- func (c *Child) WaitCalls() int64
Constants ¶
This section is empty.
Variables ¶
var ErrStopTimeout = errors.New("owned child did not complete after being signalled")
ErrStopTimeout reports that a stopped child did not reach its wait owner's completion within the caller's bound.
Functions ¶
This section is empty.
Types ¶
type Child ¶
type Child struct {
// contains filtered or unexported fields
}
Child is a started process whose wait has exactly one owner.
func Start ¶
Start starts cmd and takes ownership of waiting on it. The caller owns teardown and must arrange for Stop to run.
func (*Child) AwaitExit ¶
AwaitExit blocks until the wait owner completes, and reports whether it did so within the bound.
func (*Child) Done ¶
func (c *Child) Done() <-chan struct{}
Done is closed once the sole wait has completed and the result is stored.
func (*Child) PID ¶
PID reports the child's process id, for diagnostics and for asking the operating system about it.
The retained process object is deliberately not exported. Handing it out would hand out a second way to wait on this child, which is the one thing the ownership rule exists to prevent; callers signal through Signal instead.