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:
+22
-3
@@ -18,7 +18,18 @@ import { buildServer, gmKeyOf, makeStateDir, signIn, startServer, stopServer } f
|
||||
import { openWs } from './lib.mjs'
|
||||
import { projectRoot } from './lib.mjs'
|
||||
|
||||
const results = path.join(projectRoot, 'results')
|
||||
// Checker output is per-process scratch; tools/test.sh concatenates the shards into the committed
|
||||
// results/faults.log after the Node phase (one write per run, not an append from every process).
|
||||
const logs = path.join(projectRoot, 'run', 'logs')
|
||||
|
||||
// The 22 leak-fault cases are independent (own state dir, own server, own transcript) and each
|
||||
// costs ~4.8 s (one leak scenario + checker). tools/test.sh therefore runs this file as several
|
||||
// processes (`FFF_TEST_SHARDS`/`FFF_TEST_SHARD`) so the cases run in parallel without changing a
|
||||
// single test or assertion. Unset (a direct `node --test tools/fault.test.mjs`) = all cases here,
|
||||
// which is also what the shard maths below does for one shard.
|
||||
const SHARDS = Math.max(1, Number(process.env.FFF_TEST_SHARDS ?? 1))
|
||||
const SHARD = Math.max(0, Number(process.env.FFF_TEST_SHARD ?? 0))
|
||||
let faultCase = 0
|
||||
|
||||
// fault -> the exact set of classes the checker must report (nothing more, nothing less).
|
||||
//
|
||||
@@ -60,6 +71,9 @@ function classesOf(output) {
|
||||
.sort()
|
||||
}
|
||||
|
||||
// The cases that do not belong to FAULTS run once, in shard 0, so a sharded run executes every test
|
||||
// exactly once across the processes (and a one-shard run is still the whole file).
|
||||
if (SHARD === 0)
|
||||
test('the shipped build carries no fault hook and passes the leak test', () => {
|
||||
const bin = buildServer()
|
||||
const bytes = fs.readFileSync(bin)
|
||||
@@ -68,8 +82,9 @@ test('the shipped build carries no fault hook and passes the leak test', () => {
|
||||
})
|
||||
|
||||
for (const [fault, expected] of Object.entries(FAULTS)) {
|
||||
if (faultCase++ % SHARDS !== SHARD) continue
|
||||
test(`fault ${fault}: caught as exactly ${expected.join(' ')}`, async () => {
|
||||
fs.mkdirSync(results, { recursive: true })
|
||||
fs.mkdirSync(logs, { recursive: true })
|
||||
const stateDir = makeStateDir()
|
||||
const gmKey = gmKeyOf(stateDir)
|
||||
const s = await startServer({ stateDir, defines: ['leakfault'], env: { LEAK_FAULT: fault } })
|
||||
@@ -77,7 +92,7 @@ for (const [fault, expected] of Object.entries(FAULTS)) {
|
||||
try {
|
||||
await runLeak({ origin: s.origin, gmKey, stateDir, transcript })
|
||||
const check = runChecker(transcript, 'A')
|
||||
fs.appendFileSync(path.join(results, 'faults.log'),
|
||||
fs.appendFileSync(path.join(logs, `faults-${SHARD}.log`),
|
||||
`== fault ${fault}\n${check.output}\n`)
|
||||
assert.notEqual(check.status, 0, `the checker passed a leak (${fault}):\n${check.output}`)
|
||||
assert.deepEqual(classesOf(check.output), expected.sort(),
|
||||
@@ -91,6 +106,7 @@ for (const [fault, expected] of Object.entries(FAULTS)) {
|
||||
|
||||
// #32: an escaping failure in intent handling must still answer the request. The `dispfault` build
|
||||
// is the only build with an injection point; the shipped binary must remain incapable of faulting.
|
||||
if (SHARD === 0)
|
||||
test('the shipped build carries no dispatch fault hook', () => {
|
||||
const bin = buildServer()
|
||||
const bytes = fs.readFileSync(bin)
|
||||
@@ -107,6 +123,7 @@ async function gmSession(s) {
|
||||
return { ws, sceneId: hello.scene.id }
|
||||
}
|
||||
|
||||
if (SHARD === 0)
|
||||
test('a CatchableError inside a locked mutation: one internal ack, then the server keeps serving',
|
||||
async () => {
|
||||
const stateDir = makeStateDir()
|
||||
@@ -146,6 +163,7 @@ test('a CatchableError inside a locked mutation: one internal ack, then the serv
|
||||
}
|
||||
})
|
||||
|
||||
if (SHARD === 0)
|
||||
test('a Defect inside a locked mutation: one internal ack and no open transaction', async () => {
|
||||
const stateDir = makeStateDir()
|
||||
const s = await startServer({ stateDir, defines: ['dispfault'], env: { DISP_FAULT: 'txn-defect' } })
|
||||
@@ -167,6 +185,7 @@ test('a Defect inside a locked mutation: one internal ack and no open transactio
|
||||
}
|
||||
})
|
||||
|
||||
if (SHARD === 0)
|
||||
test('a failure after the ack was enqueued never appends a second ack', async () => {
|
||||
const stateDir = makeStateDir()
|
||||
const s = await startServer({ stateDir, defines: ['dispfault'], env: { DISP_FAULT: 'after-ack' } })
|
||||
|
||||
Reference in New Issue
Block a user