testsupport

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package testsupport holds the helpers the repository's tests share. Nothing outside tests imports it; nothing in it is product code.

Index

Constants

View Source
const AwaitRelease = `` /* 140-byte string literal not displayed */

AwaitRelease is the shell loop a scripted CLI holds itself open with until the test writes $BRIGADA_TEST_MARKERS/release. It also ends the script, with exit 1, once the test is gone: the marker directory removed (the test ended, failed or panicked and its TempDir went), or the process that started the script dead (the test binary timed out or was killed, so no cleanup ran). Without that, a test that never released left the script polling forever, reparented to init, holding whatever its stdout and stderr pointed at.

$PPID is the shell's parent at its start: the scripts are started directly (exec.Command of the script), so it names the test binary or the runner that ran them.

Variables

This section is empty.

Functions

func BuildBrigada

func BuildBrigada(t testing.TB) string

BuildBrigada builds the brigada binary once per test binary and returns its path, failing the test when the build does. The lifecycle and CLI tests run it as a real process: engines detached by clients, runners polling, the whole §13 story.

func DisableGitAutoMaintenance

func DisableGitAutoMaintenance()

DisableGitAutoMaintenance turns off git's automatic garbage collection and background maintenance for every git command this process spawns, including the ones the code under test starts. Git writes into .git in the background while those commands run, and that races a test's TempDir cleanup: RemoveAll can fail with "unlinkat .../.git: directory not empty" when git repacks the repository between the listing and the unlink. The two settings go through GIT_CONFIG_* so they reach every repository the tests create, including plain `git init` ones that no template config reaches.

This is a process-level setting meant for TestMain, not t.Setenv: tests spawn git directly and through helpers, and each of those inherits the process environment.

func GroupGone

func GroupGone(pgid int) bool

GroupGone reports whether process group pgid holds no live process: no member at all, or only zombies awaiting a reaper that is not the caller (an engine spawned by an exiting client, say). Darwin answers EPERM for a group of zombies only, so any kill error counts as gone there. Linux answers 0 while unreaped zombies remain, so /proc is scanned for members of the group and only non-zombie ones count.

func HostileToolScript

func HostileToolScript(t testing.TB) string

HostileToolScript writes a CLI script that plays a notification tool which never returns: it traps SIGTERM and parks a grandchild that holds the stdout pipe open, so the exec's context kill takes only the script itself while the pipe stays open past it. It returns the script's path; the cleanup kills the grandchild once its pid lands in the script directory's grandchild.pid, so no process outlives the test.

func NewGitRemote

func NewGitRemote(t testing.TB) string

NewGitRemote creates a local bare git remote holding one commit on main, the stand-in for a task's repo (§5.1): file-path URLs, no network, no credentials. The template is built by the process's first call; every call then writes its own copy — files and directories, empty ones included — under the test's temp dir, removed when the test ends.

func OpenStore

func OpenStore(t testing.TB) *store.Store

OpenStore opens a private, fully migrated store for one test: a copy of the process's template in the test's own temp dir, removed when the test ends. Unlike store.Open's ":memory:", the store is a file, so the pool may hand the test several connections.

func ParseProcStat

func ParseProcStat(data []byte) (state byte, pgrp int, ok bool)

ParseProcStat reads the state letter and the process group id out of the content of a /proc/<pid>/stat file. The comm field is in parentheses and may hold spaces and parentheses itself, so the fields are counted from the last ')': state is the first after it, then ppid, then pgrp.

func ProcGone

func ProcGone(pid int) bool

ProcGone reports whether pid is out of the process table — dead, or a zombie awaiting its reaper, which is as gone as a killed tree's members ever look from outside. Where /proc cannot be read, the kill syscall alone decides.

func RemoveBuiltBrigada

func RemoveBuiltBrigada()

RemoveBuiltBrigada removes the directory BuildBrigada built into, if a test built one. A package whose tests call BuildBrigada calls it from TestMain after m.Run; nothing else removes the directory, and each test binary would otherwise leave one behind in the system temp dir.

func ShortSocketPath

func ShortSocketPath(t testing.TB) string

ShortSocketPath returns a fresh, short path for one test's Unix socket, with its directory removed when the test ends. A kernel's sockaddr_un takes at most 104 bytes of path (macOS; 108 on Linux), and the obvious spot — t.TempDir(), whose name carries the test's — runs past that where temporary directories are long, so the bind fails with a bare "invalid argument". The socket gets its own short directory instead: under os.TempDir() when that leaves room, under /tmp otherwise. The result is asserted under 100 bytes — inside every kernel's cap with room to spare.

func ShortStateDir

func ShortStateDir(t testing.TB) string

ShortStateDir returns a fresh, short directory for one test's engine state, removed when the test ends. The socket inside it — <dir>/brigada.sock — must stay under the kernel's sun_path cap, which t.TempDir()'s test-named paths cannot promise; the directory is checked against the same 100-byte bound as ShortSocketPath.

Types

This section is empty.

Jump to

Keyboard shortcuts

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