Documentation
¶
Overview ¶
Package testshard lets one package's tests run as several test processes, so a package too long for go test's per-binary -timeout as one process fits it as several (iss-2610251004378066).
A package opts in from its TestMain, after any branch that re-executes the test binary as something else and before the set-up its tests need:
if code, ok := testshard.Shard(); ok {
os.Exit(code)
}
Shard does nothing unless the environment asks for shards: ShardsEnv set to a count above one, and go test running the whole package with nothing but the flags Run knows to be safe to repeat (-test.timeout, -test.count, -test.v, -test.short, -test.failfast, -test.paniconexit0, and go test's own -test.testlogfile, which each shard writes apart and Shard merges, so go test's cache reads the inputs of every shard). Then it lists the package's tests, deals them round-robin into that many shares, runs that many copies of its own binary at once, each over one share under -test.run and each with its own -test.timeout, and writes each copy's output whole, in order, once all have ended. The result is a failure when any copy failed. Any other flag (a -test.run of the caller's own, a profile, -json's test2json stream, a fuzz or bench run) runs the package as one process, as without the variable. Each shard runs the TestMain again, as a shard, and so makes the set-up its share needs.
make preflight exports the variable, and so do CI's race passes and its plain pass on an inert change (ci.yml), with the same count (iss-2610290720087336, iss-2610302058222905). The merged test log names the variable, so go test's cache keys a sharded result to the shard count and never replays it for a run as one process, which could hide a test that passes only after another in the same process.
Index ¶
Constants ¶
const ShardsEnv = "ABCD_TEST_SHARDS"
ShardsEnv is the number of test processes a package that opts in runs as.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.