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
+2 -3
View File
@@ -15,7 +15,7 @@ import crypto from 'node:crypto'
import fs from 'node:fs'
import { createPlayer, join, openWs, rawWs, sleep } from './lib.mjs'
import { gmKeyOf, makeStateDir, openAs, parseGmKey, runGmKey, startServer,
stopServer } from './withserver.mjs'
stopServer, waitForLog } from './withserver.mjs'
const sha256 = s => crypto.createHash('sha256').update(s).digest('hex')
@@ -134,8 +134,7 @@ test('logs: the negative control finds a raw key when the server leaks one', asy
env: { LEAK_FAULT: 'keylog' } })
try {
assert.equal((await join(s.origin, gmKey)).status, 303)
await sleep(100)
const log = s.log()
const log = await waitForLog(s, gmKey)
assert.ok(log.includes(gmKey), `the leaked key must be visible to the grep; log:\n${log}`)
} finally {
await stopServer(s)