Documentation
¶
Overview ¶
Package testreuse runs one of make preflight's test stages so that what Go's test cache holds for unchanged inputs is replayed (itd-2611011325421304).
Go's test cache keys a package's result on its test binary, its cacheable flags and the files and environment variables its tests read. A fresh worktree defeats all of it: its paths change the binary, its checkout gives every file a new time, and a file a test opens is hashed under its absolute path. So a stage runs from one fixed check directory per repository and account, ~/.abcd.noindex/tests/<root-sha>/, whose tree is the commit's and whose file times derive from file content, under -trimpath and one lock.
The cache cannot see what a test reads through a subprocess, a binary it builds, the clock or the network. What reruns on every check:
- The always-rerun list on the default branch (ReadList) names a package or a test. It is read from the branch, so a change's own diff does not move it. A list that is missing, does not read, or names what does not exist means nothing is reused.
- The classifier (ClassifyFiles) reads every test's source on every check. A test it finds evidence against reruns whether declared or not, and the report names it as undeclared. A file it cannot read reruns its package.
- The check directory holds no .git and git may not walk above it. An always-rerun test runs in the worktree, where git answers, with -count=1.
The hosted run is the backstop: it passes -count=1 on every test step, on every pull request and merge-queue entry.
The sync reads every file of the tree back against the commit before a line runs and again after, and a receipt is minted only from a stage's record of that exact tree. One check holds the lock at a time, for the lines that use the tree; the rerun lines run outside it.
A race stage's binary is built differently, so race results reuse race results only, never the unit stage's, and the unit stage's never a race run's.
Index ¶
Constants ¶
const ( ExitUsage = 2 ExitBusy = 3 )
Exit codes beyond go test's own: a recipe mistake, and a check that gave up waiting for another to leave the directory.
const ListPath = ".abcd/work/always-rerun-tests.txt"
ListPath is where the always-rerun list lives on the default branch.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Stage string
Args []string // what follows `go test` in the recipe
Worktree string
Home string
Stdout io.Writer
Stderr io.Writer
// Fresh is a release cut: nothing is reused and nothing is synced, and the
// report's mode says so.
Fresh bool
// CachedTimeout is the -timeout of a line whose results are to be reused.
// go test's cache key holds the timeout, and a stage's own takes one of two
// values with the load, so a fixed one keeps a result reusable however busy
// the machine is. Empty keeps the stage's.
CachedTimeout string
// LockWait bounds the wait for another check on this directory.
LockWait time.Duration
// Uid is the account that must own the check directory.
Uid int
// AfterWait, when a check has waited for the lock, takes -p and -timeout again.
// An error stops the stage.
AfterWait func() (p, timeout string, err error)
// RaceGate is the race gate, which a race stage that waited passes again.
RaceGate func() error
}
Config is one stage's run.
type Counts ¶
Counts is a stage's reuse: Reused of Packages had a result replayed, Whole of them with no test run at all, and Ran names the packages any test ran in.
type Declared ¶
Declared is one line of the always-rerun list: a package, or every package under one when the pattern ends in /..., optionally narrowed to named tests.
type List ¶
type List []Declared
List is the parsed always-rerun list.
func ParseList ¶
ParseList reads the list. One entry a line: a package path relative to the module, then the names of the tests when not all of them, then # and why it reads what the test cache cannot see. A line that does not read refuses the whole list, and with it all reuse: a declaration that cannot be read must not become a test that is reused.
type Package ¶
type Package struct {
ImportPath string
Dir string
GoFiles []string
Imports []string
TestGoFiles []string
XTestGoFiles []string
// IgnoredGoFiles holds a test file built for another stage alone, whose tests
// a list line can name.
IgnoredGoFiles []string
TestImports []string
XTestImports []string
}
Package is what the check reads of one package from go list.
type PackageRoute ¶
type PackageRoute struct {
Path string
// Rerun is the reason the whole package always reruns, when it does.
Rerun string
// Tests are the tests that always rerun when only some do, by name, each
// with its reason.
Tests map[string]string
}
PackageRoute is where a package's tests go.
type Plan ¶
type Plan struct {
Cached []string
Split []PackageRoute
Rerun []PackageRoute
}
Plan routes a stage's packages: those reused wherever nothing changed, those run whole on every check, and those split into the two by test.
func MakePlan ¶
func MakePlan(pkgs []string, rels map[string]string, verdicts map[string]Verdict, list List, narrowed bool) Plan
MakePlan applies the list and the classifier's verdicts to pkgs, in the order the stage names them. rels gives each package's path from the module root. narrowed says the stage's own -run selects its tests, which leaves no way to add a second selection, so a package with any test to rerun reruns whole under that -run.
type StageReport ¶
StageReport is one go test line's record for the receipt: which commit and tree it checked, how, and what it reused.
type SyncStats ¶
SyncStats is what a sync did to the check directory.
func Sync ¶
Sync makes dir's tree exactly the commit's: every tracked file with its mode and content-derived time, every directory with a time derived from the names in it, and nothing else. It reads every file back and keeps one only when its bytes are the commit's, and it writes only what differs, so a commit that changes one file writes one file and a repository whose tree has thousands of files creates that churn once. Every write goes through an os.Root on the tree, so nothing a test or a commit left there takes one elsewhere. A sync interrupted anywhere leaves a tree the next one repairs: a file is renamed into place with its time already set, what a test or a crash left is removed, and a directory's time is set last.
type Tally ¶
type Tally struct {
// contains filtered or unexported fields
}
Tally reads go test's result lines.
type Verdict ¶
Verdict is the classifier's reading of one package's test files: a reason the whole package always reruns, or the tests that do, each with its reason.
func ClassifyFiles ¶
ClassifyFiles reads the named test files of one package. spawns says that the package's tests can start a subprocess through the code they link: its own test files or anything in its import closure imports os/exec. helpers holds what the module's test-helper packages reach, by import path and symbol. A file that does not parse sends the whole package to the always-rerun line: what cannot be read cannot be shown safe.