test: wait for the async log line instead of racing it

Under the fan-out a test that greps server.log right after an ack can lose:
the logger writes the line after the ack. waitForLog polls to a deadline and
the assertions are unchanged (the line must still appear; absence checks still
run on the same snapshot). Fixes the one observed assertion failure
(fault.test.mjs's intent_failed line) and the same latent race in the
opaque_refused and startup-line checks.
This commit is contained in:
2026-11-21 21:42:34 +01:00
parent 514104f897
commit 100df38230
7 changed files with 44 additions and 19 deletions
+4 -3
View File
@@ -14,7 +14,7 @@ import fs from 'node:fs'
import { DatabaseSync } from 'node:sqlite'
import path from 'node:path'
import { runLeak, runChecker } from './leak.mjs'
import { buildServer, gmKeyOf, makeStateDir, signIn, startServer, stopServer } from './withserver.mjs'
import { buildServer, gmKeyOf, makeStateDir, signIn, startServer, stopServer, waitForLog } from './withserver.mjs'
import { openWs } from './lib.mjs'
import { projectRoot } from './lib.mjs'
@@ -144,8 +144,9 @@ test('a CatchableError inside a locked mutation: one internal ack, then the serv
assert.deepEqual({ ...db.prepare('SELECT x, y FROM entity WHERE id = ?').get(tok.id) },
{ x: 100, y: 100 })
db.close()
// One log event names the intent and the error class, never the message or payload.
const log = s.log()
// One log event names the intent and the error class, never the message or payload. The
// logger writes after the ack, so wait for the line instead of racing it.
const log = await waitForLog(s, /ERROR intent_failed intent=token\.move reqId=\d+ class=ValueError message=unhandled/)
assert.match(log, /ERROR intent_failed intent=token\.move reqId=\d+ class=ValueError message=unhandled/)
assert.equal(log.includes('injected fault'), false, 'the exception message is not logged')