testenv

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 11 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 testenv establishes process-wide isolation for test binaries that shell out to tmux.

Any package whose tests reach tmux — directly, or indirectly through internal/tty — must isolate, because the alternative is that `go test ./...` operates on the developer's own tmux server. That is not a hypothetical: td-4d99ae found 66 orphaned control-mode clients and 18 orphaned servers accumulated over about a week of test runs, which drove the real server past its file-descriptor limit and made every Sidecar tmux call intermittently fail. td-8d18de is the same lesson learned the harder way.

TMUX_TMPDIR relocates tmux's default socket, so tmux resolves to a private server for this process and every tmux child it spawns. Nothing an isolated suite does can reach the developer's sessions, whatever session name a future test happens to pick.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsolateTmux

func IsolateTmux() (socket string, teardown func(), err error)

IsolateTmux points every tmux command this process runs at a throwaway server and returns the socket path plus a teardown.

Teardown kills the server by explicit socket path rather than running a bare `tmux kill-server`. A bare kill-server trusts the environment to still be pointing somewhere private; if anything has disturbed TMUX_TMPDIR by then it destroys the developer's own server and every session on it. -S names the file we created, so the blast radius cannot leave this temp dir.

The returned teardown is safe to call more than once and from more than one goroutine.

func Main

func Main(m *testing.M) int

Main runs m with tmux isolated, tears down, and returns the exit code. Callers do:

func TestMain(m *testing.M) { os.Exit(testenv.Main(m)) }

Teardown also runs on SIGINT/SIGTERM, so an interrupted run does not leak. It cannot run when the binary dies by panic or by `go test` timeout — Go exits those paths without unwinding TestMain — which is why teardown leaves a reachable socket behind rather than an orphan with no path, and why `make reap-test-tmux` exists.

func OnSignal

func OnSignal(fn func()) (stop func())

OnSignal runs fn if the process is interrupted, then restores the default disposition and re-raises so the exit status still reflects the signal.

Packages that drive TestMain themselves — because they isolate a second axis as well — should call this alongside IsolateTmux, so an interrupted run gets the same cleanup Main provides.

The returned stop waits for an in-flight handler to finish, so a signal arriving exactly as m.Run returns cannot leave teardown running concurrently with the caller's own teardown call.

func SocketPath

func SocketPath(tmuxTmpDir string) string

SocketPath is where tmux puts its default socket under a given TMUX_TMPDIR.

Types

This section is empty.

Jump to

Keyboard shortcuts

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