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:
@@ -6,7 +6,7 @@ import fs from 'node:fs'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { listeningSockets } from './lib.mjs'
|
||||
import { buildServer, makeStateDir, startServer, stopServer, withServer } from './withserver.mjs'
|
||||
import { buildServer, makeStateDir, startServer, stopServer, withServer, waitForLog } from './withserver.mjs'
|
||||
|
||||
test('withserver brings the server up and /healthz answers 200 JSON', async () => {
|
||||
await withServer(async s => {
|
||||
@@ -17,7 +17,8 @@ test('withserver brings the server up and /healthz answers 200 JSON', async () =
|
||||
assert.equal((await fetch(`${s.origin}/nope`)).status, 404)
|
||||
assert.equal((await fetch(`${s.origin}/healthz`, { method: 'POST' })).status, 405)
|
||||
// flags reached the config and the start line: the harness origin and the fixed loopback bind
|
||||
assert.match(s.log(), new RegExp(`server_start origin=${s.origin} .* bind=127\\.0\\.0\\.1`))
|
||||
const startLog = await waitForLog(s, new RegExp(`server_start origin=${s.origin} .* bind=127\\.0\\.0\\.1`))
|
||||
assert.match(startLog, new RegExp(`server_start origin=${s.origin} .* bind=127\\.0\\.0\\.1`))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user