From c1d726c105571267db16206e15ba30f2d172fcdb Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 5 Nov 2026 11:04:47 +0100 Subject: [PATCH] Relay test waits for the late page instead of a fixed 2.5 s On a busy CI runner the page took longer than that to load and answer, and the test failed although the server did proceed. --- tests/agent-relay.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/agent-relay.test.js b/tests/agent-relay.test.js index 2966901..21074f9 100644 --- a/tests/agent-relay.test.js +++ b/tests/agent-relay.test.js @@ -22,6 +22,8 @@ const PORT = 8799 + (process.pid % 500); // dodge a busy por const tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-relay-')); const wait = (ms) => new Promise((r) => setTimeout(r, ms)); +// Waits until ok() holds, up to ms: a busy CI runner can take seconds to load a page, so no fixed delay is enough. +const until = async (ok, ms = 20000) => { const t0 = Date.now(); while (!ok() && Date.now() - t0 < ms) await wait(50); return ok(); }; // The relay in-process, riding a real http.Server (the same createRelay the servers host): no child to leak, and // 'listening' means the first dial cannot race the bind. @@ -373,7 +375,7 @@ test('the MCP server answers the handshake at once and waits for the game page', assert.match(m.stderr(), /waiting for the game page/); a = page({ seed: 4 }); a.ev("ACT.start({});S.cash=444000;compute()"); - await wait(2500); + await until(() => /ready/.test(m.stderr())); assert.match(m.stderr(), /ready/, 'the server proceeded once the page answered'); assert.equal(await m.json('state', { path: 'cash' }), 444000, 'and drives the late page'); } finally { stop(a); await m.kill(); }