Skip to content

Testing and landing

Automated checks decide what lands. Each change is tested before it lands, main is tested after, and a change that breaks main is found and reverted on its own.

In Atoll Forge, automated checks decide what lands. No one has to review a change for it to land, unless a landing requirement or a request asks for a person’s approval. Testing follows Google’s Test Automation Platform: each change is tested on its own before it lands, main is tested continuously after, and a change that breaks main is found and reverted. There is no merge queue.

Testing before and after landingBefore landing: a submitted change is checked on a runner with main's .forge/test, in a sandbox, on exactly its commit; it lands only if the check passes, and otherwise goes back to its agent. After landing: main's newest landing is tested against the last that passed; a failure is bisected to the first failing landing, confirmed by running it and its parent again, and reverted by a change of the forge's own that goes through the same gate. If the confirmation disagrees, the failure is logged as flaky.BEFORE LANDINGSubmitthe change'slatest commitCheck on a runnermain's .forge/test, sandboxed,on exactly this commitLandon main, with thecheck in its recordfails: the change goes back to its agentAFTER LANDINGTest mainnewest landing, againstthe last that passedBisectto the first landingwhose tests failConfirmit fails again, andits parent passesReverta change of the forge's,through the gatedisagrees: logged as flakyA revert is a change like any other: it lands only once its own check passes.Testing before and after landingBefore landing: a submitted change is checked on a runner with main's .forge/test, in a sandbox, on exactly its commit; it lands only if the check passes, and otherwise goes back to its agent. After landing: main's newest landing is tested against the last that passed; a failure is bisected to the first failing landing, confirmed by running it and its parent again, and reverted by a change of the forge's own that goes through the same gate. If the confirmation disagrees, the failure is logged as flaky.BEFORE LANDINGSubmitthe change's latest commitCheck on a runnermain's .forge/test, sandboxed, on exactly this commitLandon main, with the check in its recordfails: the change goes back to its agentAFTER LANDINGTest mainnewest landing, against the last that passedBisectto the first landing whose tests failConfirmit fails again, and its parent passesReverta change of the forge's, through the gateconfirm disagrees: logged as flaky
Before landing, a runner checks each change with main's test program. After landing, main is tested as fast as runners allow; a failure is bisected to the landing that caused it, confirmed, and reverted through the same gate.

The repository’s test program

A repository says how it is tested with one executable file, .forge/test, which agents write like any other code. A runner runs it in the change’s tree. It lists the tests it is going to run, runs them, and reports each one’s result; the change passes if the program exits 0, every listed test has a result, and none failed. The forge selects no tests itself: the program asks the repository’s own build tool which tests the change affects, and runs those.

#!/bin/sh
# .forge/test: check each shell script the change touches.
set -eu
mkdir -p "$FORGE_OUT/tests"
printf 'syntax tap\nend\n' > "$FORGE_OUT/tests/inventory"
report="$FORGE_OUT/tests/syntax.tap"
grep '\.sh$' "$FORGE_CHANGED" > "$FORGE_OUT/scripts" || true
# The plan, before any test runs: one test a script.
echo "1..$(grep -c . "$FORGE_OUT/scripts" || true)" > "$report"
status=0
while read -r path; do
  # A `#` in a test's name is escaped, or it would start a directive.
  name=$(printf '%s' "$path" | sed 's/\\/\\\\/g; s/#/\\#/g')
  if [ ! -f "$path" ] || sh -n "$path"; then
    echo "ok - $name" >> "$report"
  else
    echo "not ok - $name" >> "$report"
    status=1
  fi
done < "$FORGE_OUT/scripts"
exit "$status"

The program runs in a sandbox on the runner and sees only this:

Path What it holds
/work/src the change’s files, read-only; its working directory
/work/forge main’s .forge/ folder, read-only; the program is /work/forge/test
/work/changed every path the change edits, one a line
/work/out an empty directory it may write, such as for build outputs
/work/home an empty directory it may write, its HOME

Its environment names the commits involved, each in hex: FORGE_COMMIT, the change’s; FORGE_BASE, its parent’s; and FORGE_TESTS_AT, the commit of main whose .forge/ runs. FORGE_OBJECT_FORMAT says which hash names them: sha256, 64 hex digits, as a repository is made by default, or sha1, 40, for one made with --objects sha1. FORGE_CHANGED and FORGE_OUT are the paths above. Exit statuses 125 and 127 belong to the sandbox, as docker run’s do: it could not be set up, or the program could not be started.

Every test accounted for

A test run that ends early can still exit 0: one test calling exit(0) ends a Rust test binary with success while another test fails. So the exit status alone never passes a check. The program writes its reports under $FORGE_OUT/tests:

File What it holds
inventory one line a suite, <suite> junit, <suite> results or <suite> tap, then a last line end
<suite>.expected for junit and results: the tests the suite is going to run, one a line, from the framework’s own list mode
<suite>.junit.xml a JUnit XML report; a test is its classname, a tab and its name
<suite>.results the forge’s own format, one JSON object a line: {"name": "...", "outcome": "passed"}, "failed" or "skipped"
<suite>.tap a TAP 13 or 14 stream, without subtests; its plan 1..N comes before the first test, and its tests are the numbers 1 to N

The runner reads them itself, and the check fails when:

  • a suite the inventory names lacks a file, or the folder holds anything the inventory does not name;
  • the inventory does not end with end, which it only does once every suite is listed;
  • a listed test has no result, or any test failed, listed or not;
  • a report does not read as its format, a name holds a control character, or the reports pass a limit: 1,025 files, 64 MiB, a million tests, 4 KiB a name.

A skipped test counts as accounted for, and is counted. A change that selects no tests writes a suite with an empty list, such as a TAP stream of 1..0. Of several results for one test, a failure stands over a pass, and a pass over a skip. A JUnit test reported flakyFailure or flakyError and no failure passed on a retry, and is counted as flaky.

The signed record of a check keeps the counts and a digest of every test’s outcome, or the reason the reports could not be counted, never a test’s name: a test’s name may say what a folder holds, and not everyone who sees a record may read it. The runner’s own output names the first 20 tests missing or failed.

Rust, with cargo-nextest

cargo-nextest lists tests before it runs them and writes JUnit XML. Keep its settings in .forge/, so that no change loosens them for its own check:

# .forge/nextest.toml
[store]
dir = "/work/out/nextest"

[profile.ci]
retries = 0 # a test that fails once fails the check

[profile.ci.junit]
path = "junit.xml"
#!/bin/sh
# .forge/test: a Rust workspace, its dependencies vendored, as the sandbox has no network.
set -eu
reports="$FORGE_OUT/tests"
mkdir -p "$reports"
export CARGO_TARGET_DIR="$FORGE_OUT/target"
nextest() {
  cargo nextest "$@" --locked --config-file /work/forge/nextest.toml --profile ci
}
# Every test that will run, named as the report names it: its binary, a tab, its name.
nextest list --message-format json |
  jq -r '."rust-suites"[] | ."binary-id" as $binary | .testcases | to_entries[]
    | select(.value."filter-match".status == "matches") | "\($binary)\t\(.key)"' \
  > "$reports/unit.expected"
printf 'unit junit\nend\n' > "$reports/inventory"
status=0
nextest run || status=$?
cp /work/out/nextest/ci/junit.xml "$reports/unit.junit.xml"
exit "$status"

Give list and run the same selection arguments, so that the list names what runs. nextest runs no doctests; a repository that wants them lists and reports them as another suite.

Before landing

Once main holds .forge/test, a submitted change waits for a runner’s check of exactly its commit. A pass sends it on to land; a failure opens the change again, with a failed event, and submitting it again runs a new check.

The check always runs main’s .forge/, never the change’s own, as Zuul runs a project’s job configuration only once it has merged. A change that edits .forge/ also needs a person’s approval, so no change edits the script that judges it without one.

That guards the script, not the verdict. The change’s own code runs in its check, in its own tree, and code written to cheat can make a failing test pass, by how it configures its build tool, or by writing the missing results itself before it ends the run. Accounting for every test catches a run that ends early by mistake. A passing check shows the change broke nothing the tests catch by mistake, not that it did not cheat on purpose.

Until main holds a test program there is nothing to check, and changes land on their requirements alone. That is why the quickstart lands at once.

After landing

main is tested continuously, with no interval to set. Whenever no test of main is running, its newest landing is tested against the last landing that passed, so one run covers as many landings as the runners’ pace allows. When a run fails, the landings in between are bisected to the one whose tests fail where the landing before passes: the culprit.

The forge then confirms before it blames. The culprit’s test and its parent’s run once more each, as Chromium’s Findit does to rule out a flaky test:

  • If the culprit fails again and its parent passes again, the culprit is logged as broke, and the forge writes its revert as a change of its own: main’s files with the culprit’s edits taken back. The revert goes through the gate like any change, its own check included. When it lands, the culprit’s change is logged as reverted.
  • If they disagree, the failure is logged as flaky, and nothing is reverted.

A landing whose edits main has since changed again cannot be reverted cleanly; the forge leaves it to an agent or a person.

Landings that cannot be tested

A landing whose files include contents that were later purged cannot be tested as it was: those files are withheld from every reader, runners included. A test of what is left would run on a tree that never existed, so it proves nothing either way. The forge skips such a landing, as git bisect skip skips a commit, and logs it as mainSkipped:

  • The forge decides. It finds the purged files itself before it queues a test, so no runner is sent a landing it cannot test. If contents are purged after a job was queued, the runner finds them withheld, runs nothing, and reports the job skipped. The forge checks that claim against its own records before it accepts it.
  • Bisection goes around a skipped landing. It tests the untested landing nearest the middle instead.
  • When only skipped landings are left between the last good landing and the first bad one, the first bad landing could be any of them, or the bad one itself. Each of their changes is logged as suspected, and nothing is reverted, since no single culprit can be confirmed.
  • A confirmation that cannot run leaves the culprit suspected too, not broke or flaky, and nothing is reverted. This happens when contents were purged after bisection named the culprit.

A skip is not a test result, so it gets no receipt. It comes from the purge’s own record, which the organization’s log already keeps.

Runners

Runners are the machines that run checks, and only checks run by runners gate landings. An agent can run tests on its own change for quick feedback, but that never lets a change land.

A runner is enrolled by an administrator, and is born from the forge, so it is never in the line of the change’s author. The forge pushes each job to a runner over the runner’s open connection, as soon as the runner has room. The runner signs the result of each check, and the result becomes part of the landing’s record.

A runner holds its jobs by a lease, renewed by heartbeats, as Nomad’s clients hold theirs. If its heartbeats stop, its jobs go to another runner once the lease runs out.

Setting one up takes three commands. On the runner machine, make its key:

af-runner key /etc/af-runner/key

An administrator enrolls the public key it prints:

af enroll-runner <PUBLIC_KEY> --name build-01

Then start the runner with the ID the enrollment printed:

af-runner run --address forge.example.com:7777 --id <RUNNER_ID> \
    --key /etc/af-runner/key --work /var/lib/af-runner --system /usr --capacity 4

Next

Type to search…

↑↓ navigate↵ selectEsc close