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
+11 -6
View File
@@ -8,7 +8,7 @@ import assert from 'node:assert/strict'
import fs from 'node:fs'
import { DatabaseSync } from 'node:sqlite'
import { createPlayer, namePlayer, sleep } from './lib.mjs'
import { gmKeyOf, makeStateDir, openAs, startServer, stopServer } from './withserver.mjs'
import { gmKeyOf, makeStateDir, openAs, startServer, stopServer, waitForLog } from './withserver.mjs'
import { V7_DDL, V7_WALLS } from './schema7fixture.mjs'
const CELL = 32
@@ -175,7 +175,8 @@ test('explored is strictly per player, before and after a restart', async () =>
assert.deepEqual(sorted(after.alice), sorted(before.alice))
assert.deepEqual(sorted(after.bob), sorted(before.bob))
assert.ok(!after.alice.has(cellOf(3100, 3800)), 'still strictly per player after the restart')
assert.match(s.log(), /explored_loaded players=2 chunks=[1-9]/, s.log())
const log2 = await waitForLog(s, /explored_loaded players=2 chunks=[1-9]/)
assert.match(log2, /explored_loaded players=2 chunks=[1-9]/, log2)
} finally {
await stopServer(s)
fs.rmSync(stateDir, { recursive: true, force: true })
@@ -209,7 +210,8 @@ test('restart: every player\'s explored area is identical before and after (SIGT
// The start is more than one vision radius from the last position, so these cells cannot come
// from recomputing sight: they are the loaded chunks.
assert.ok(after.has(cellOf(200, 200)))
assert.match(s.log(), /explored_loaded players=1 chunks=[1-9]/, s.log())
const log1 = await waitForLog(s, /explored_loaded players=1 chunks=[1-9]/)
assert.match(log1, /explored_loaded players=1 chunks=[1-9]/, log1)
} finally {
await stopServer(s)
fs.rmSync(stateDir, { recursive: true, force: true })
@@ -411,7 +413,8 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
}
const s = await startServer({ stateDir })
try {
assert.match(s.log(), /db_ready .*schema_version=8 applied=4/, s.log())
const boot4 = await waitForLog(s, /db_ready .*schema_version=8 applied=4/)
assert.match(boot4, /db_ready .*schema_version=8 applied=4/, boot4)
// The old data is served unchanged through the product surface.
const alice = { id: 2, key: 'ALIC-ALIC-ALIC-ALIC-ALIC' }
const conn = await openAs(s.origin, alice.key)
@@ -483,7 +486,8 @@ test('migration: a schema-7 wall/token/character fixture maps to typed storage a
let before
let s = await startServer({ stateDir })
try {
assert.match(s.log(), /db_ready .*schema_version=8 applied=1/, s.log())
const boot1 = await waitForLog(s, /db_ready .*schema_version=8 applied=1/)
assert.match(boot1, /db_ready .*schema_version=8 applied=1/, boot1)
const db = new DatabaseSync(dbPath)
try {
const cols = db.prepare("SELECT name FROM pragma_table_info('wall')").all().map(r => r.name)
@@ -528,7 +532,8 @@ test('migration: a schema-7 wall/token/character fixture maps to typed storage a
// Second start: the migration runner writes nothing and the data is byte-identical.
s = await startServer({ stateDir })
try {
assert.match(s.log(), /db_ready .*schema_version=8 applied=0/, s.log())
const boot0 = await waitForLog(s, /db_ready .*schema_version=8 applied=0/)
assert.match(boot0, /db_ready .*schema_version=8 applied=0/, boot0)
const db = new DatabaseSync(dbPath)
try {
assert.deepEqual(readWallRows(db), before.walls)