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:
2026-11-21 21:40:07 +01:00
parent 30b35592c7
commit 1ac46b4969
9 changed files with 396 additions and 49 deletions
+13 -14
View File
@@ -5,7 +5,7 @@ import { spawn, spawnSync } from 'node:child_process'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { baseUrl, freePort, join, openWs, projectRoot, refuseLivePort, sleep } from './lib.mjs'
import { baseUrl, cachedNimBuild, freePort, join, openWs, projectRoot, refuseLivePort, sleep } from './lib.mjs'
const SERVER_BIN = path.join(projectRoot, 'run', 'test', 'server')
@@ -14,11 +14,12 @@ function nimblePkgs() {
return path.join(nimbleDir, 'pkgs2')
}
let builtAt = null
const builtCache = new Map()
// Build the real binary from the working tree. `defines` adds `-d:` flags (a leak-fault build,
// DESIGN 10.3); each variant lands in its own file so the clean build is never overwritten.
// The build is cached by source+flags and shared across the concurrently-running test files
// (lib.mjs cachedNimBuild); a serial run pays each variant once, a parallel run pays nothing extra.
export function buildServer(opts = {}) {
const defines = opts.defines ?? []
const key = defines.join(',')
@@ -26,19 +27,17 @@ export function buildServer(opts = {}) {
? SERVER_BIN
: path.join(projectRoot, 'run', 'test', `server-${defines.join('-').replace(/[^A-Za-z0-9-]/g, '')}`))
if (builtCache.has(key)) return builtCache.get(key)
fs.mkdirSync(path.dirname(out), { recursive: true })
// Worktree-local nimcache: Nim's default (~/.cache/nim/<project>_d) is shared by every checkout of
// the repo, so two worktrees building at once corrupt each other's object files. run/ is
// gitignored, and the variant name keeps a fault build separate from the clean build's cache.
const cache = path.join(projectRoot, 'run', 'nimcache', path.basename(out))
const args = ['c', '--hints:off', '--mm:orc', `--nimblePath:${nimblePkgs()}`,
`--nimcache:${cache}`, ...defines.map(d => `-d:${d}`), `-o:${out}`,
path.join('server', 'main.nim')]
const r = spawnSync('nim', args, { cwd: projectRoot, encoding: 'utf8' })
if (r.status !== 0) throw new Error(`nim c server/main.nim ${defines.join(' ')} failed:\n${r.stdout}\n${r.stderr}`)
builtAt = out
builtCache.set(key, out)
return out
const built = cachedNimBuild({
out,
roots: ['server'],
extra: `${defines.join(',')}\n${nimblePkgs()}\n`,
nimArgs: tmp => ['c', '--hints:off', '--mm:orc', `--nimblePath:${nimblePkgs()}`,
`--nimcache:${cache}`, ...defines.map(d => `-d:${d}`), `-o:${tmp}`,
path.join('server', 'main.nim')],
})
builtCache.set(key, built)
return built
}
export function makeStateDir(prefix = 'fffvtt-') {