ci: compile the split packages' tests side by side, not in turn
Each split package's go test -list (which compiles its test binary) ran one after another, so the last packages' shards started late: host's at +86 s on a450449, and its slowest shard set the 221 s gate. Now every list starts at once, near the top of the gate, and each package's shards start as soon as its own list is ready, in whatever order the lists finish. Each list is still its own go command, so the fence still counts exactly one package's tests. The gate also prints how long each list took.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+69
−12
.amadan/test-gate.sh+69 −12
CI failed — run details
diff --git a/.amadan/test-gate.sh b/.amadan/test-gate.sh| index 0632a0f37..aca787753 100755 |
| --- a/.amadan/test-gate.sh |
| +++ b/.amadan/test-gate.sh |
| @@ -51,8 +51,9 @@ |
| # how long it took, so a slow run says whether it was short of cores. |
| set -eu |
| -# Heaviest first: discovery compiles each package's tests in turn, so the |
| -# packages that dominate the wall clock get their shards started earliest. |
| +# Heaviest first: shards start in this order once their package's tests |
| +# have compiled, and the packages that dominate the wall clock should not |
| +# queue behind the others. |
| : "${TEST_SPLIT=./internal/console=24 ./internal/edge=4 ./internal/activator=4 ./internal/host=6 .=5 ./internal/grouproll=2}" |
| weights=$(pwd)/.amadan/test-weights.tsv |
| gate_t0=$(date +%s) |
| @@ -168,6 +169,29 @@ start launchctx sh -c 'cd launchctx && go vet ./... && go test ./... -count=1' |
| start vet go vet ./... |
| start gofmt sh -c 'fmt_out=$(gofmt -l .); if [ -n "$fmt_out" ]; then echo "gofmt needed:"; echo "$fmt_out"; exit 1; fi; echo "gofmt -l .: clean"' |
| +# The split packages' test lists, all at once. `go test -list` compiles the |
| +# test binary, which the shards then reuse from the build cache. One after |
| +# another the compiles held the last packages' shards back by a minute and |
| +# a half (host's started at +86 s on 2026-11-11); side by side, each |
| +# package waits only for its own. The deal below reads each list in turn, |
| +# as before. Each is its own go command, so a package's list is exactly |
| +# that package's: the fence counts on it. |
| +# A package's tag names its files, its shards and a shell variable, so |
| +# anything but letters, digits and _ becomes _. |
| +split_tag() { echo "$1" | sed 's|^\./||; s|^\.$|root|; s|[^A-Za-z0-9_]|_|g'; } |
| +for spec in $TEST_SPLIT; do |
| + tag=$(split_tag "${spec%=*}") |
| + ( |
| + set +e |
| + t0=$(date +%s) |
| + go test -count=1 -list '.*' "${spec%=*}" >"$out/list-$tag.raw" 2>&1 |
| + echo $? >"$out/list-$tag.rc" |
| + echo $(($(date +%s) - t0)) >"$out/list-$tag.secs" |
| + ) & |
| + started="$started list-$tag:$!" |
| + eval "list_pid_$tag=\$!" |
| +done |
| + |
| # Everything not split runs as one ordinary `go test`. Packages are named |
| # by import path, so match TEST_SPLIT's directories through `go list`. |
| split_paths="" |
| @@ -209,26 +233,30 @@ if [ "${GATE_WEIGHTS:-}" = 1 ]; then |
| shard_json=-json |
| fi |
| -for spec in $TEST_SPLIT; do |
| +# deal_split deals one split package's listed tests onto its shards and |
| +# starts them. |
| +deal_split() { |
| + spec=$1 |
| dir=${spec%=*} |
| shards=${spec#*=} |
| discover go list "$dir" >"$out/go-list" |
| pkg=$(cat "$out/go-list") |
| - tag=$(echo "$dir" | sed 's|^\./||; s|^\.$|root|; s|/|_|g') |
| + tag=$(split_tag "$dir") |
| - # -list compiles the test binary, which the shards below then reuse |
| - # from the build cache. Benchmarks are listed but never run by a plain |
| - # `go test`, so they are left out of the deal. |
| - if ! discover go test -count=1 -list '.*' "$dir" >"$out/list-$tag.raw" 2>&1; then |
| - cp "$out/list-$tag.raw" "$out/$tag.log" |
| + # This package's list, started above, has finished. A list with no |
| + # status file was killed before it could write one. Benchmarks are |
| + # listed but never run by a plain `go test`, so they are left out of |
| + # the deal. |
| + if [ "$(cat "$out/list-$tag.rc" 2>/dev/null || echo 1)" -ne 0 ]; then |
| + cp "$out/list-$tag.raw" "$out/$tag.log" 2>/dev/null || true |
| fail_job "$tag" "could not list the tests in $pkg" |
| - continue |
| + return |
| fi |
| grep -E '^(Test|Example|Fuzz)' "$out/list-$tag.raw" | sort -u >"$out/list-$tag" || true |
| listed=$(wc -l <"$out/list-$tag") |
| if [ "$listed" -eq 0 ]; then |
| fail_job "$tag" "go test -list found no tests in $pkg, which is not believable" |
| - continue |
| + return |
| fi |
| # Longest-processing-time first: heaviest test onto the least-loaded |
| @@ -249,7 +277,7 @@ for spec in $TEST_SPLIT; do |
| dealt=$(wc -l <"$out/deal-$tag") |
| if [ "$dealt" -ne "$listed" ]; then |
| fail_job "$tag" "dealt $dealt of $listed tests in $pkg" |
| - continue |
| + return |
| fi |
| i=0 |
| @@ -265,6 +293,26 @@ for spec in $TEST_SPLIT; do |
| if [ "$launched" -ne "$listed" ]; then |
| fail_job "$tag-deal" "launched $launched of $listed tests in $pkg" |
| fi |
| +} |
| + |
| +# Each package's shards start as soon as its own list is ready, whatever |
| +# order the lists finish in. A list writes its .secs file last. |
| +pending=$TEST_SPLIT |
| +while [ -n "$pending" ]; do |
| + left="" |
| + for spec in $pending; do |
| + tag=$(split_tag "${spec%=*}") |
| + if [ -e "$out/list-$tag.secs" ]; then |
| + eval "wait \$list_pid_$tag" || true |
| + deal_split "$spec" |
| + else |
| + left="$left $spec" |
| + fi |
| + done |
| + pending=$left |
| + if [ -n "$pending" ]; then |
| + sleep 1 |
| + fi |
| done |
| wait |
| @@ -307,6 +355,15 @@ for name in $names; do |
| [ "$rc" -eq 0 ] || failed="$failed $name" |
| done |
| +# How long each split package's tests took to compile and list, side by |
| +# side from the start: a shard cannot start before its package's list. |
| +lists="" |
| +for spec in $TEST_SPLIT; do |
| + tag=$(split_tag "${spec%=*}") |
| + lists="$lists $tag $(cat "$out/list-$tag.secs" 2>/dev/null || echo '?') s," |
| +done |
| +echo "=== lists:${lists%,}" |
| + |
| # CPU used against wall clock. The shell's `times` covers every job it |
| # has waited for, and each job waited for its go test and the test |
| # binaries under it, so this is the whole gate's CPU. Busy cores well |