#!/bin/sh # mesh-check-toolchain: go # # The controller's own check (novox/hq ADR 0237 as amended): the second layer of a pull request's merge # check, `mesh/repo-check`, run by the build seat in the mesh's Go toolchain — and by hand: # `MESH_TEST_POSTGRES=… sh merge-check.sh`. # # The gate — every machine composed with this change's controller, which judges itself — is the build # seat's first layer (`mesh/merge-gate`), run because the mesh's module graph builds `mesh-controller` # from this repository; it is not repeated here. This is the code's own quality and its suite: # # 1. formatted and vetted, with and without the build tag `integration`; # 2. the unit level: `go test ./...` untagged and without the race detector, timed and held to a bound # (unit_bound below): a test with no database, bus, running service or other process (novox/hq ADR 0391, # how-we-build section 5). With a bound set, over it the check fails and names the slowest tests (issue 895); # 3. the integration level: the whole suite with `-tags integration`, packages in parallel, against the # throwaway store the build seat raised at the release the mesh runs; every live test on a bus of its own # (internal/testbus), so nothing is serialised. Under the race detector when the toolchain has a C # compiler, and said when it has not. # # **A test that starts a bus, a store or another process, or composes the whole mesh, carries # `//go:build integration`** as the first line of its file; a file that held both kinds is two files # (`_integration_test.go` beside `_test.go`). Each level says its test count and its time. # # Exit 0 is a pass; anything else fails `mesh/repo-check` with the last line printed. set -eu export GOFLAGS=-mod=vendor GOPROXY=off # **The unit level's bound, in seconds** (issue 895): the slowest package's own test time of the untagged run, the # compile not counted. A run over it fails the check and names the slowest tests. It is 5 s since the tests carry the # `integration` tag (design 47 milestone 3): the slowest packages, cmd/mesh-controller and internal/catalogue, measured # 2.6-2.8 s on a quiet machine in about 2000 small tests each, and the build node runs the store tests beside this run # and other work besides, so twice the measure. How-we-build section 5 asks 1 s for the whole unit suite: issue 1055 # (a catalogue loaded once per package run, fewer source-scanning tests, the timed run started alone). unit_bound=5 # judge_store_tests says each listed test of one package as `go test -v` reported it, and counts in $missing each # that did not pass: $1 the package, $2 go test's exit status, $3 the file holding its output, then the names. # A result is found anywhere in a line, not only at its start: when a test's last output leaves a line open, # `go test -v` writes `--- PASS: (…)` on that same line (novox/hq issue 515). A package whose go test # exits non-zero fails even when each listed test said PASS — a TestMain or a leak checker can fail after them. judge_store_tests() { pkg=$1 status=$2 out=$3 shift 3 for name in "$@"; do line=$(grep -oE -- "--- (PASS|FAIL|SKIP): $name \([^)]*\)" "$out" | tail -n 1 || true) echo " $pkg ${line:-"--- NOT RUN: $name"}" case "$line" in "--- PASS: "*) ;; *) missing=$((missing + 1)) ;; esac done if [ "$status" -ne 0 ]; then echo " $pkg FAIL: go test exited $status" missing=$((missing + 1)) fi } # judge_unit_run says the unit level as `go test -v` reported it and fails when it was over the bound: $1 the file # holding the output of the untagged `go test -v` of every package (packages one after another, each ending in its # `ok