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.
This commit is contained in:
parent
13768c61cb
commit
c1d726c105
1 changed files with 3 additions and 1 deletions
|
|
@ -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 tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-relay-'));
|
||||||
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
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
|
// 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.
|
// '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/);
|
assert.match(m.stderr(), /waiting for the game page/);
|
||||||
a = page({ seed: 4 });
|
a = page({ seed: 4 });
|
||||||
a.ev("ACT.start({});S.cash=444000;compute()");
|
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.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');
|
assert.equal(await m.json('state', { path: 'cash' }), 444000, 'and drives the late page');
|
||||||
} finally { stop(a); await m.kill(); }
|
} finally { stop(a); await m.kill(); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue