test: fan out the gates and build shared binaries once
Every Nim test file and every Node test file is already isolated (own temp state dir, free ports, own server/nginx), so run them FFF_TEST_JOBS at a time (default half the cores, capped at 8) instead of one at a time. The real server (clean, leakfault, dispfault) and the leak checker are built once per source+flags and shared across the parallel files; nimcaches are worktree-local so two checkouts cannot race on them. The 22 independent fault cases are sharded across processes. The wall-clock gate files (persistence, tiles; e2e map/fog/fogbench/ perf) still run alone first so their budgets are not measured under the suite's own load. No test or assertion changes.
This commit is contained in:
+145
-10
@@ -1,20 +1,155 @@
|
||||
#!/usr/bin/env bash
|
||||
# devbox run test: Nim in-process tests first, then the Node black-box harnesses (DESIGN 10.4).
|
||||
# Nim gates Node: a red Nim suite stops the run (the Node stage takes seconds, but no point).
|
||||
# Logs land in results/ like the other gates.
|
||||
# Gate summaries land in results/; per-job logs are scratch under run/logs/.
|
||||
#
|
||||
# Parallelism: every Nim test file compiles and runs independently (own nimcache per file name,
|
||||
# their own temp state dirs, no ports), and every Node test file is its own process with its own
|
||||
# server/nginx/state dir. Both phases therefore run FFF_TEST_JOBS at a time (default: half the
|
||||
# cores, capped at 8; FFF_TEST_JOBS=1 serialises). The two Node files whose *assertions* are
|
||||
# wall-clock gates (persistence's move-ack budget, tiles' lock-free burst) stay in a serial phase
|
||||
# so their numbers are not measured under the suite's own load.
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
mkdir -p results
|
||||
if ! nimble test -y > results/nimble-test.log 2>&1; then
|
||||
cat results/nimble-test.log
|
||||
. tools/jobs.sh
|
||||
mkdir -p results run/logs
|
||||
fff_setup_tmpdir
|
||||
JOBS=$(fff_test_jobs)
|
||||
|
||||
# Warm the shared Nim build cache (server, the two fault variants, the leak checker) while the Nim
|
||||
# tests compile: every Node test file then starts from a cached binary instead of racing to build.
|
||||
rm -f run/logs/prebuild.rc
|
||||
( node tools/prebuild.mjs > run/logs/prebuild.log 2>&1; echo $? > run/logs/prebuild.rc ) &
|
||||
|
||||
# --- Nim in-process tests -----------------------------------------------------------------------
|
||||
# Same files and command nimble test runs (all tests/*.nim, debug, -r), but with a bounded pool.
|
||||
NIM_LOG_DIR=run/logs/nim
|
||||
rm -rf "$NIM_LOG_DIR"; mkdir -p "$NIM_LOG_DIR"
|
||||
PKGS=${NIMBLE_DIR:-$PWD/.devbox/nimble}/pkgs2
|
||||
nim_one() {
|
||||
local f=$1 base
|
||||
base=$(basename "$f" .nim)
|
||||
# Worktree-local nimcache: the global ~/.cache/nim/<file>_d is shared by every checkout on the
|
||||
# host, so two worktrees testing at once would write each other's object files. run/ is
|
||||
# gitignored and the cache persists across runs, so a warm run pays nothing extra.
|
||||
nim c -d:NimblePkgVersion=0.1.0 --nimblePath:"$PKGS" --path:. \
|
||||
--nimcache:"$PWD/run/nimcache/test-$base" -r --hints:off \
|
||||
"$f" > "$NIM_LOG_DIR/$base.log" 2>&1
|
||||
echo $? > "$NIM_LOG_DIR/$base.log.rc"
|
||||
}
|
||||
nim_files=(tests/*.nim)
|
||||
running=0
|
||||
for f in "${nim_files[@]}"; do
|
||||
nim_one "$f" &
|
||||
running=$((running + 1))
|
||||
if [ "$running" -ge "$JOBS" ]; then
|
||||
wait -n
|
||||
running=$((running - 1))
|
||||
fi
|
||||
done
|
||||
wait
|
||||
nim_rc=0
|
||||
: > results/nimble-test.log
|
||||
for f in "${nim_files[@]}"; do
|
||||
base=$(basename "$f" .nim)
|
||||
log="$NIM_LOG_DIR/$base.log"
|
||||
cat "$log" >> results/nimble-test.log
|
||||
rc=$(cat "$log.rc" 2>/dev/null || echo 1)
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
nim_rc=1
|
||||
printf '\n=== FAILED: %s (exit %s) ===\n' "$f" "$rc" >> results/nimble-test.log
|
||||
fi
|
||||
done
|
||||
cat results/nimble-test.log
|
||||
if [ "$nim_rc" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
cat results/nimble-test.log
|
||||
# One file at a time: every harness builds and runs the same real binary (run/test/server) and
|
||||
# starts real servers; serialising removes build/write races. Ports and state dirs are isolated.
|
||||
node --test --test-concurrency=1 --test-reporter=spec tools/*.test.mjs > results/node-test.log 2>&1
|
||||
rc=$?
|
||||
|
||||
# The shared build cache must be ready before the fan-out (the prebuild itself is not a gate: a
|
||||
# Node test file builds what it needs on its own; a prebuild failure shows up there).
|
||||
while [ ! -f run/logs/prebuild.rc ]; do sleep 0.2; done
|
||||
if [ "$(cat run/logs/prebuild.rc)" -ne 0 ]; then
|
||||
cat run/logs/prebuild.log
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Node black-box harnesses -------------------------------------------------------------------
|
||||
# Wall-clock gate files first, alone (their ack/burst budgets are load-sensitive), then the rest at
|
||||
# FFF_TEST_JOBS. Every file test still runs exactly once; tools/evidence.mjs reads the combined log.
|
||||
NODE_LOG_DIR=run/logs/node
|
||||
rm -rf "$NODE_LOG_DIR"; mkdir -p "$NODE_LOG_DIR"
|
||||
rm -f run/logs/faults-*.log
|
||||
node_task() { # $1 logbase, $2 file, $3 shard (optional), $4 shards (optional)
|
||||
local base=$1 file=$2
|
||||
if [ -n "${3:-}" ]; then
|
||||
FFF_TEST_SHARD="$3" FFF_TEST_SHARDS="$4" node --test --test-reporter=spec "$file" \
|
||||
> "$NODE_LOG_DIR/$base.log" 2>&1
|
||||
else
|
||||
node --test --test-reporter=spec "$file" > "$NODE_LOG_DIR/$base.log" 2>&1
|
||||
fi
|
||||
echo $? > "$NODE_LOG_DIR/$base.log.rc"
|
||||
}
|
||||
node_pool() { # $1 concurrent tasks, then "logbase|file[|shard|shards]" specs
|
||||
local pool=$1; shift
|
||||
local running=0 spec base file shard shards
|
||||
for spec in "$@"; do
|
||||
IFS='|' read -r base file shard shards <<< "$spec"
|
||||
node_task "$base" "$file" "$shard" "$shards" &
|
||||
running=$((running + 1))
|
||||
if [ "$running" -ge "$pool" ]; then
|
||||
wait -n 2>/dev/null
|
||||
running=$((running - 1))
|
||||
fi
|
||||
done
|
||||
wait
|
||||
}
|
||||
NODE_SERIAL=(tools/persistence.test.mjs tools/tiles.test.mjs)
|
||||
SERIAL_SPECS=()
|
||||
for f in "${NODE_SERIAL[@]}"; do
|
||||
SERIAL_SPECS+=("$(basename "$f" .test.mjs)|$f")
|
||||
done
|
||||
node_pool 1 "${SERIAL_SPECS[@]}"
|
||||
# fault.test.mjs's independent cases are sharded across processes; when the gate is serialised,
|
||||
# one shard keeps the same single process (and thus the same serial run).
|
||||
FAULT_SHARDS=$JOBS
|
||||
[ "$JOBS" -le 4 ] || FAULT_SHARDS=4
|
||||
PARALLEL_SPECS=()
|
||||
for f in tools/*.test.mjs; do
|
||||
case " ${NODE_SERIAL[*]} " in
|
||||
*" $f "*) continue ;;
|
||||
esac
|
||||
# import-scale is its own script (`devbox run import-scale`, #83): a 16384 px memory/fd soak,
|
||||
# not part of the pre-push gate.
|
||||
[ "$f" = tools/importscale.test.mjs ] && continue
|
||||
if [ "$f" = tools/fault.test.mjs ]; then
|
||||
for i in $(seq 0 $((FAULT_SHARDS - 1))); do
|
||||
PARALLEL_SPECS+=("fault-$i|$f|$i|$FAULT_SHARDS")
|
||||
done
|
||||
else
|
||||
PARALLEL_SPECS+=("$(basename "$f" .test.mjs)|$f")
|
||||
fi
|
||||
done
|
||||
node_pool "$JOBS" "${PARALLEL_SPECS[@]}"
|
||||
rc=0
|
||||
: > run/logs/node-test-serial.log
|
||||
for spec in "${SERIAL_SPECS[@]}"; do
|
||||
base=${spec%%|*}
|
||||
cat "$NODE_LOG_DIR/$base.log" >> run/logs/node-test-serial.log
|
||||
[ "$(cat "$NODE_LOG_DIR/$base.log.rc")" -eq 0 ] || rc=1
|
||||
done
|
||||
: > run/logs/node-test-parallel.log
|
||||
for spec in "${PARALLEL_SPECS[@]}"; do
|
||||
base=${spec%%|*}
|
||||
cat "$NODE_LOG_DIR/$base.log" >> run/logs/node-test-parallel.log
|
||||
[ "$(cat "$NODE_LOG_DIR/$base.log.rc" 2>/dev/null || echo 1)" -eq 0 ] || rc=1
|
||||
done
|
||||
cat run/logs/node-test-serial.log run/logs/node-test-parallel.log > results/node-test.log
|
||||
# The fault checker's per-shard output, in shard order, is the committed evidence file.
|
||||
: > results/faults.log
|
||||
for i in $(seq 0 $((FAULT_SHARDS - 1))); do
|
||||
[ -f "run/logs/faults-$i.log" ] && cat "run/logs/faults-$i.log" >> results/faults.log
|
||||
done
|
||||
cat results/node-test.log
|
||||
[ $rc -eq 0 ] || exit $rc
|
||||
[ "$rc" -eq 0 ] || exit "$rc"
|
||||
# #36: the group map's evidence is only proof if the named tests actually ran and passed. This is a
|
||||
# separate post-run step because groups.test.mjs runs inside the suite it would have to inspect.
|
||||
node tools/evidence.mjs results/node-test.log || exit 1
|
||||
|
||||
Reference in New Issue
Block a user