Functions
func AddedJobID(t *testing.T, result Result) string
func AssertPairOutcome(t *testing.T, r Result)
func BuildRotari(path string) error
BuildRotari builds cmd/rotari at path for a conformance test binary.
Commands that run the binary must call TrackBuildInputs.
func CommandEnv(vars []string, dir string) []string
CommandEnv is vars with PWD set to dir, as a shell sets it to the directory
as the user named it. Without it, os.Getwd returns the resolved path,
which differs where the temporary directory is under a symbolic link,
as /var is on macOS.
func GuardedCommands(project string) map[string][]string
GuardedCommands are the project commands that a running or interrupted
project rejects. Queue edits are not among them: the queue holds only the
next run's jobs.
func JobProcesses(t *testing.T, root, job string) int
func KeepOnFailure(t *testing.T, root string, transcript *Transcript)
KeepOnFailure keeps the evidence of a failed test: when t has failed,
its state directory root is moved to a new directory under
os.TempDir()/FailedDirName, with the transcript beside it as commands.log,
and the place is logged. A passing test keeps nothing. Register it before
the cleanups that stop the test's servers and processes, so that it runs
after them.
func KillProcessGroup(pid int) error
func KillStrays(t *testing.T, root string)
func KillSupervisors(t *testing.T, root string)
KillSupervisors kills the supervisor processes of runs under root, as a
crash would, and leaves their jobs running. It returns once they are gone,
so a caller that then stops the jobs cannot let a supervisor record their
results.
func MemoryTempDir(t *testing.T) string
MemoryTempDir returns a directory on /dev/shm when it is writable, removed
when the test ends, and t.TempDir otherwise. jj syncs its operation log to
disk on every snapshot, which takes seconds on a host busy with synchronous
writes, so jj repositories made by tests live in memory.
func NonUTF8NamesAllowed(t interface {
Helper()
Logf(string, ...any)
Fatal(...any)
}, dir string) bool
NonUTF8NamesAllowed reports whether the file system under dir holds a name
that is not UTF-8. macOS (APFS) refuses one with EILSEQ; there a test checks
everything else and leaves such names out.
func PairAdapter(command string) string
One execution classification shared by the inventory and runners. Missing
adapters are deferred explicitly rather than counted as passing tests.
func PairHasFlag(flags []PairFlag, name string) bool
func PairIntersect(a, b []string) []string
func PairMutationRevision(t *testing.T, e *Env) string
func ProcessArgs(pid int) ([]string, bool, error)
ProcessArgs returns pid's arguments, or false when it is not running.
func ProcessEnvironment(pid int) ([]string, error)
ProcessEnvironment returns pid's environment as NAME=VALUE entries: from
/proc on Linux and from ps -E elsewhere, where entries follow the arguments
split at spaces. It fails when pid is gone or not this user's.
func Run(m *testing.M) int
func TrackBuildInputs(t testing.TB)
TrackBuildInputs makes a cached test result depend on rotari's sources.
BuildRotari runs `go build` in a subprocess, which Go's test cache does not
observe, so a cached conformance result would survive a change to rotari.
The cache does record files the test process stats while tests run (not in
TestMain), so every command that runs the built binary calls this: it stats
each file under the module's cmd and internal directories, plus go.mod and
go.sum, once per test binary.
func WaitForInterrupted(t *testing.T, e *Env, project string)
func WaitUntil(t *testing.T, timeout time.Duration, done func() (bool, string))
Types
type ActiveRun struct {
Project string
RunID string
Jobs []string
}
type CoordinatorProcess struct {
Host string `json:"host"`
PID int `json:"pid"`
PIDNamespace string `json:"pid_namespace"`
ProcessStart string `json:"process_start"`
}
func CurrentCoordinator(t *testing.T) CoordinatorProcess
func ProcessIdentity(t *testing.T, pid int) CoordinatorProcess
type Env struct {
T *testing.T
Root string
Base string
Master string
// Has unexported fields.
}
func NewEnv(t *testing.T) *Env
func (e *Env) CheckState(project string) string
func (e *Env) Command(args ...string) *exec.Cmd
Command returns an unstarted rotari command in e's environment, for a test
that talks to the process itself, such as over its stdin.
func (e *Env) CreateFinishedRun() FinishedRun
func (e *Env) ExportFinishedRun(project string) string
func (e *Env) FinishedJobRun(project string) (runID, attemptID string)
func (e *Env) HTTPDo(method, url string, headers map[string]string, body string) HTTPResult
HTTPDo sends one request with headers; a "Host" header sets the request's
Host. body, when not empty, is sent as JSON.
func (e *Env) HTTPGet(url string) HTTPResult
func (e *Env) HTTPPostJSON(url string, body any) HTTPResult
func (e *Env) In(dir string) *Env
In returns a copy of e whose commands run in dir.
func (e *Env) JobExitStatus(project, jobID string) string
func (e *Env) MustRotari(args ...string) Result
func (e *Env) OrphanRun(project, script string) string
func (e *Env) Rotari(args ...string) Result
func (e *Env) RotariRun(args ...string) Result
RotariRun runs a run or retry that must start a run, whatever its jobs do.
A refusal to start also exits 1, like a run whose jobs failed, so it fails
the test with the command's output unless a new run directory appeared in
e's basedir or one the arguments name.
func (e *Env) Setenv(name, value string)
Setenv sets name in the environment of e's later commands.
func (e *Env) StartRun(project string, count int, async bool, runArgs ...string) ActiveRun
func (e *Env) StartTableView(path string, args ...string) string
StartTableView starts rotari tableview on path and returns its URL.
func (e *Env) StartWeb(args ...string) string
func (e *Env) WithVar(name, value string) *Env
func (e *Env) Without(name string) *Env
type FinishedRun struct {
Project string
RunID string
OKJob string
BadJob string
BadAttempt string
}
type FlagPair struct{ A, B PairFlag }
func CommandFlagPairs(c PairCommand) []FlagPair
type HTTPResult struct {
Status int
Body string
}
type PairCommand struct {
Name string `json:"name"`
Flags []PairFlag `json:"flags"`
}
func ReadPairSchema(t *testing.T, e *Env) []PairCommand
type PairFixture struct {
E *Env
Project, Run, Bad, Array, Config string
Jobs []string
}
func NewPairFixture(t *testing.T) PairFixture
func (f PairFixture) Sample(t *testing.T, flag PairFlag) []string
type PairFlag struct {
Name string `json:"name"`
ValueName string `json:"value_name"`
Values []string `json:"values"`
}
type PairMutationFixture struct {
PairFixture
Initial PairSavedTree
// Current is the tree as last observed after an invocation; Restore
// diffs against it.
Current *PairSavedTree
Revision string
SecondRun string
Manifest string
}
func NewPairMutationFixture(t *testing.T) PairMutationFixture
type PairMutationResult struct {
Process Result
State map[string]string
}
type PairSavedFile struct {
Path string
Mode fs.FileMode
At time.Time
Data []byte
Dir bool
}
type PairSavedTree []PairSavedFile
A byte-for-byte initial tree, including directory mtimes used by latest-run
lookup. All paths are relative to the harness-owned temporary root.
No active supervisor/job is allowed while this snapshot is captured or
restored.
func SavePairTree(t *testing.T, root string) PairSavedTree
func (tree PairSavedTree) Observation(t *testing.T) map[string]string
Only the project's newly written meta.updated_at is nondeterministic.
All other content (IDs, queue definitions, results, registry, modes) stays
exact.
func (tree PairSavedTree) Raw() map[string]string
func (tree PairSavedTree) Restore(t *testing.T, root string, current PairSavedTree)
Restore returns root to tree, given current, the snapshot taken after the
last invocation. It rewrites only entries that differ, which matters on
network filesystems where rewriting the whole tree per invocation dominated
the runtime. Every entry's path, type, mode, and modification time is then
checked against tree; contents are exact because unchanged entries had equal
contents in current and changed ones are rewritten from tree.
type Process struct {
PID, PPID, PGID int
// Args are the command-line arguments. On Linux they are exact; elsewhere
// they come from ps and are split at spaces, so an argument holding a space
// reads as several. Tests match paths without spaces and whole words.
Args []string
}
Process is one entry of the process table, as tests look at it from outside.
func MustProcesses(t interface {
Helper()
Fatalf(string, ...any)
}) []Process
MustProcesses is Processes, failing the test on an error rather than letting
a caller find nothing and pass.
func Processes() ([]Process, error)
Processes lists the processes this user can see: from /proc on Linux,
and from ps elsewhere. A process that has exited but is not yet reaped has
no arguments.
func (p Process) CommandLine() string
CommandLine joins the arguments with spaces, for substring matches.
func (p Process) HasArg(arg string) bool
HasArg reports whether one argument is exactly arg.
type Result struct {
Args []string
Code int
Stdout string
Stderr string
}
func PairInvoke(t *testing.T, e *Env, args ...string) Result
Adapters own isolation and restoration for mutating commands. Finished runs
ensure --follow exits; the deadline is a failure bound, never an expected
result. It is 20 s: 5 s was exceeded by cancel --wait on a loaded macOS
runner under the race detector, and 20 s still stops short of the 30-second
grace period a cancel waits when its job does not end, so that fault still
shows.
func (r Result) String() string
type Transcript struct {
// Has unexported fields.
}
Transcript records the rotari commands a test runs: when each started,
in which directory, and, for commands run to completion, their exit code and
full output. It is written out only when the test fails.
func (transcript *Transcript) Finished(args []string, code int, stdout, stderr string, elapsed time.Duration)
Finished records a command that ran to completion.
func (transcript *Transcript) Started(dir string, args []string)
Started records a command that is about to start.