Server-run engine: review fixes
The review of track T2 found these; each has a test in tests/mp-sim-*.
- Built-ins: an arg, array entry or draft that is '__proto__', 'constructor'
or 'prototype' is refused by the envelope check and again by the realm
(free text may still say them). After every realm call the trampoline
checks the realm's built-ins against what they were at load; a realm
whose built-ins changed answers {srvErr, polluted} and is replaced from
the worker's mark like one that timed out. S as one JSON per key is a
null-prototype object, so the epilogue's for…in never reads a prototype.
- A realm that cannot be built again is never used again: rebuild() tries
once more without the packed R, and when that fails too the network is
dropped (NO_REALM), and the engine tells the host (opts.onLost).
- A mark that fails or runs out of time changes nothing: it clears the old
mark first, the realm is built again from its own save, never from an
older mark, and the reply names the mark. A day rebuilds only from its
own attempt's mark.
- A day whose alone or nets is not a list is refused whole (ERR); a throw
in a load or day step answers that call, never ends the worker.
- An exit counts against the session the worker was running (the worker
says so before each job and step), else as before. Workers of their own
are capped (opts.maxOwn, 4): past that a session is given up.
- A worker that exits before it is ready is started again after a pause
that doubles; after 5 in a row every call answers SIM_DOWN.
- The game text is read and compiled once, in createEngine: a src/ that
does not compile throws there, and every worker, also one started after
an exit, runs the game engine.simId names.
- A damaged route memory never breaks a save that loads (routed from
nothing, logged), and only a server network loads (S.mp.sim, Normal).
- Routing memory (UI.rk, UI.rkR) is kept by the in-place restore and
carried in rt (rk), so a reloaded or rolled-back network skips the same
routings as the one that kept going.
- A fresh realm takes over the fx of the one it replaces (the mark's after
a failed call, all of them after a read): badges, windows and toasts
waiting for a page are not lost to a timeout.
- Windows: the stand-in elements answer querySelector from what was
written (a [data-x] marker) and have a working classList, never the
inert proxy that said every window is open. A request's ctx may name the
open window, ctx.win = {k, ui} (mp-sim-acts.js WINDOWS: bstd, routing,
charter, ops, pie), with the view state only the page holds (the
intern's POP, the pie window's tab and POP), checked in the realm. This
is an addition to the contract of design 5.8 that the page (T4) sends.
The stand-in is hidden again after an act.
- xpBuild's via is a TEXT arg (256): a six-span express fits.
- actDone, askDone and pulled carry ms, the worker time of the call;
engine.mem() and engine.has(code, nid) are public; prefs() passes a
realm's err through; after close() every call rejects CLOSED.
- The fake engine fails as the engine does (NO_REALM, ERR, a load without
a save, a day of an unknown session or naming an unloaded network,
GAVE_UP, SIM_DOWN, CLOSED, onLost), its greet says its one-shots once and
never 'told'; a test runs the same edge calls on both.
- SIM_DRAFT is built from DRAFT_TYPES.
This commit is contained in:
parent
3b8c331556
commit
9597d89079
11 changed files with 879 additions and 211 deletions
|
|
@ -5,8 +5,17 @@
|
|||
// everything back; actions report only the UI they changed; a session's day holds back loads; unwatched networks stay
|
||||
// bounded; realms do not share their intrinsics; every call is answered, whatever a load holds; and a session whose load
|
||||
// takes its worker down gets a worker of its own, then is given up, while the others keep their places.
|
||||
// Review fixes: an arg that names a built-in is refused, and a realm whose built-ins changed is replaced; a mark that
|
||||
// runs out of time undoes nothing; a fresh realm takes over the fx waiting for a page; a network whose realm cannot be
|
||||
// built again is dropped and the host told; a day with bad lists is refused, never the worker's end; an exit blames the
|
||||
// session that was running; a worker that cannot start backs off, then SIM_DOWN; the game is read once (a src/ that
|
||||
// does not compile fails at start, a respawned worker runs the same game); a damaged route memory still loads, a save
|
||||
// that is no server network does not; and the fake engine answers the same edge calls with the same codes.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { createEngine, snapWith } = require('../scripts/lib/mp-sim-engine');
|
||||
const { checkEvent, checkFx, fixture } = require('./lib/mp-sim-shape');
|
||||
const { MP, TEST, ROOMY, bigScenic, msg, begin, checked } = require('./lib/mp-sim-play');
|
||||
|
|
@ -44,6 +53,7 @@ test('a new network: begin, a snapshot, its welcome, actions, days, a what-if, v
|
|||
// Actions: the update with the result is version v; the tutorial moves on the server.
|
||||
const a1 = checked(await E.act(code, nid, msg('launchBB', { city: 'fra' })));
|
||||
assert.deepEqual([a1.outcome, a1.v, a1.epoch], ['applied', 2, L.epoch]);
|
||||
assert.ok(a1.ms > 0 && G.ms >= 0, 'the worker time of a call, for the rate limit');
|
||||
const u1 = updOf(a1);
|
||||
assert.equal(u1.from, 1);
|
||||
assert.deepEqual(u1.acts.map((x) => x.rid), [JSON.parse(JSON.stringify(a1.rid))]);
|
||||
|
|
@ -369,17 +379,236 @@ test('a session whose load takes its worker down: twice, a worker of its own; on
|
|||
} finally { await W.close(); }
|
||||
});
|
||||
|
||||
test('a polluted prototype stays in its own realm', async () => {
|
||||
test('a polluted prototype stays in its own realm, and that realm is replaced at its next call', async () => {
|
||||
const code = 'P0WWVT', a = 'poll0001', b = 'poll0002';
|
||||
(await E.load(code, [begin(a), begin(b)])).forEach(checked);
|
||||
const ep = checked(await E.pull(code, a, {})).epoch;
|
||||
assert.equal(await ev(code, a, 'Object.prototype.polluted=1;Array.prototype.evil=()=>1;return ({}).polluted'), 1);
|
||||
assert.deepEqual(await ev(code, b, 'return [({}).polluted===undefined,[].evil===undefined]'), [true, true]);
|
||||
assert.equal(({}).polluted, undefined, 'nor the host');
|
||||
const D = await day(code, 1, [a, b]);
|
||||
assert.deepEqual([D.nets[a].day, D.nets[b].day], [1, 1]);
|
||||
assert.deepEqual([D.nets[a].day, D.nets[a].retried, D.nets[b].day, D.nets[b].retried], [1, true, 1, undefined]);
|
||||
assert.notEqual(checked(await E.pull(code, a, {})).epoch, ep, 'a fresh realm');
|
||||
assert.deepEqual(await ev(code, a, 'return [({}).polluted===undefined,[].evil===undefined]'), [true, true]);
|
||||
await E.unload(code);
|
||||
});
|
||||
|
||||
test('an arg that names a built-in is refused; an act that changes the built-ins all the same leaves a fresh realm and the network as before', async () => {
|
||||
const code = 'PR0T0S', nid = 'prot0001';
|
||||
checked((await E.load(code, [begin(nid)]))[0]);
|
||||
checked(await E.act(code, nid, msg('launchBB', { city: 'fra' })));
|
||||
const ep = checked(await E.pull(code, nid, {})).epoch;
|
||||
// The envelope refuses it (tests/mp-sim-contract.test.js); a body that got past it, the realm refuses too.
|
||||
const r0 = checked(await E.act(code, nid, { ...msg('launchBB', { city: 'ams' }), args: { city: '__proto__' } }));
|
||||
assert.deepEqual([r0.outcome, r0.why], ['rejected', 'an arg names a built-in']);
|
||||
assert.equal(await ev(code, nid, 'for(const k in {})return k;return null;'), null);
|
||||
// An act that writes through a prototype all the same (by hand here): the reply says so, the realm that saw it is
|
||||
// never used again, and the network is as it was before the act.
|
||||
const s0 = await ev(code, nid, 'return JSON.stringify(S)');
|
||||
await ev(code, nid, '{const f=ACT.buildPop;ACT.buildPop=a=>{f(a);Object.prototype.bb={d:null};};}return 1;');
|
||||
const r1 = checked(await E.act(code, nid, msg('buildPop', { city: 'ams' })));
|
||||
assert.deepEqual([r1.t, r1.what, /built-ins of the realm changed: Object\.prototype\.bb/.test(r1.msg)], ['err', 'throw', true]);
|
||||
const P = checked(await E.pull(code, nid, { snap: true }));
|
||||
assert.notEqual(P.epoch, ep, 'a fresh realm');
|
||||
assert.equal(await ev(code, nid, 'return JSON.stringify(S)'), s0, 'the act undone');
|
||||
assert.equal(await ev(code, nid, "for(const k in {})return k;return ACT.buildPop.toString().includes('prototype')"), false, 'clean, with the game\'s own act');
|
||||
assert.equal(checked(await E.act(code, nid, msg('buildPop', { city: 'ams' }))).outcome, 'applied', 'and it plays on');
|
||||
// One that also throws (its finally blocks ran: S went back in place, the prototype did not): the same.
|
||||
await ev(code, nid, "{const f=ACT.buildPop;ACT.buildPop=a=>{f(a);Array.prototype.evil=1;throw new Error('and threw');};}return 1;");
|
||||
const r2 = checked(await E.act(code, nid, msg('buildPop', { city: 'dus' })));
|
||||
assert.deepEqual([r2.t, /Array\.prototype\.evil/.test(r2.msg)], ['err', true]);
|
||||
assert.deepEqual(await ev(code, nid, "for(const k in [])return k;return [!!S.pops.ams,!!S.pops.dus]"), [true, false]);
|
||||
await E.unload(code);
|
||||
});
|
||||
|
||||
test('a mark that runs out of time changes nothing: no applied action or day is undone, and the reply names the mark', async (t) => {
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: { ...ROOMY, mark: 300 } });
|
||||
t.after(() => W.close());
|
||||
const { ev } = on(W);
|
||||
const code = 'MARKT0', nid = 'mark0001';
|
||||
checked((await W.load(code, [begin(nid)]))[0]);
|
||||
assert.equal(checked(await W.act(code, nid, msg('buildPop', { city: 'ams' }))).outcome, 'applied');
|
||||
checked(await W.day(code, { d: 1, nets: [nid] }));
|
||||
const ep = checked(await W.pull(code, nid, {})).epoch;
|
||||
await ev(code, nid, 'srvMark=function(){for(;;){}};return 1;');
|
||||
const r = checked(await W.act(code, nid, msg('buildPop', { city: 'dus' })));
|
||||
assert.deepEqual([r.t, r.what, r.msg], ['err', 'timeout', 'marking the network took longer than 300 ms']);
|
||||
assert.deepEqual(await ev(code, nid, 'return [S.day,!!S.pops.ams,!!S.pops.dus]'), [1, true, false], 'what was applied stays');
|
||||
assert.notEqual(checked(await W.pull(code, nid, {})).epoch, ep, 'built again from its own save');
|
||||
// A day whose mark runs out of time: built again from its own save, and the day plays in the fresh realm.
|
||||
await ev(code, nid, 'srvMark=function(){for(;;){}};return 1;');
|
||||
const D = checked(await W.day(code, { d: 2, nets: [nid] }));
|
||||
assert.deepEqual([D.nets[nid].day, D.nets[nid].retried, D.nets[nid].err], [2, true, undefined]);
|
||||
assert.deepEqual(await ev(code, nid, 'return [S.day,!!S.pops.ams]'), [2, true]);
|
||||
});
|
||||
|
||||
test('a fresh realm after a timeout takes over the fx waiting for a page: badges, windows and toasts', async (t) => {
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: { ...ROOMY, day: 600, act: 400 } });
|
||||
t.after(() => W.close());
|
||||
const { ev } = on(W);
|
||||
const code = 'FXKEEP', nid = 'fxkp0001';
|
||||
checked((await W.load(code, [begin(nid)]))[0]);
|
||||
checked(await W.pull(code, nid, { snap: true }));
|
||||
const ep = checked(await W.pull(code, nid, {})).epoch;
|
||||
const waiting = (id) => `srvFx(['badge',{id:'${id}',v:'oncall'}]);showWin();toast('still waiting');`;
|
||||
const kept = (P) => { const k = JSON.parse(P.snap).keep.map((f) => (f[0] === 'badge' ? 'badge:' + f[1].id : f[0] + ':' + f[1])); return k; };
|
||||
// A day that runs out of time once (the fx were waiting before it), then plays in a fresh realm.
|
||||
await ev(code, nid, waiting('probe') + '{const f=ddosTick;let once=true;ddosTick=function(){f();if(once){once=false;for(;;){}}};}return 1;');
|
||||
const D = checked(await W.day(code, { d: 1, nets: [nid] }));
|
||||
assert.deepEqual([D.nets[nid].day, D.nets[nid].retried], [1, true]);
|
||||
const P = checked(await W.pull(code, nid, { snap: true }));
|
||||
assert.notEqual(P.epoch, ep);
|
||||
assert.ok(kept(P).includes('badge:probe') && kept(P).includes('modal:win'), `kept: ${kept(P)}`);
|
||||
assert.ok(JSON.parse(P.upd).fx.some(([k, p]) => k === 'toast' && p.h === 'still waiting'), 'and the toast');
|
||||
// An action that runs out of time: the same, and its own fx are not among them.
|
||||
await ev(code, nid, waiting('probe2') + "ACT.buildPop=()=>{toast('mine');for(;;){}};return 1;");
|
||||
const r = checked(await W.act(code, nid, msg('buildPop', { city: 'ams' })));
|
||||
assert.deepEqual([r.t, r.what], ['err', 'timeout']);
|
||||
const P2 = checked(await W.pull(code, nid, { snap: true }));
|
||||
assert.notEqual(P2.epoch, P.epoch);
|
||||
assert.deepEqual(kept(P2), ['badge:probe2', 'modal:win']);
|
||||
const fx2 = JSON.parse(P2.upd).fx;
|
||||
assert.ok(fx2.some(([k, p]) => k === 'toast' && p.h === 'still waiting') && !fx2.some(([k, p]) => k === 'toast' && p.h === 'mine'));
|
||||
});
|
||||
|
||||
test('a network whose realm cannot be built again is dropped: the host is told, its calls answer NO_REALM, the others play on', async (t) => {
|
||||
const lost = [];
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: { ...ROOMY, act: 400 }, onLost: (c, nids, why) => lost.push([c, nids, why]) });
|
||||
t.after(() => W.close());
|
||||
const { ev } = on(W);
|
||||
const code = 'DR0PPD', a = 'lost0001', b = 'lost0002';
|
||||
(await W.load(code, [begin(a), begin(b)])).forEach(checked);
|
||||
// Its marks are no saves that load (as a corrupt state would be), and an act runs for ever inside opsQuiet.
|
||||
await ev(code, a, "{const m0=srvMark;srvMark=function(i){const r=m0(i);return r.slice(0,r.indexOf('\\n'))+'\\n{\"cash\":';};}ACT.buildPop=()=>opsQuiet(()=>{for(;;){}});return 1;");
|
||||
const r = checked(await W.act(code, a, msg('buildPop', { city: 'ams' })));
|
||||
assert.deepEqual([r.t, r.what, /the network was dropped/.test(r.msg)], ['err', 'timeout', true]);
|
||||
assert.deepEqual(lost.map(([c, nids]) => [c, nids]), [[code, [a]]]);
|
||||
assert.match(lost[0][2], /rebuilding the realm failed/);
|
||||
assert.deepEqual([W.has(code, a), W.has(code, b)], [false, true]);
|
||||
await assert.rejects(W.pull(code, a, {}), (e) => e.code === 'NO_REALM');
|
||||
await assert.rejects(W.act(code, a, msg('buildPop', { city: 'ams' })), (e) => e.code === 'NO_REALM');
|
||||
assert.deepEqual(Object.keys(checked(await W.day(code, { d: 1, nets: [a, b] })).nets), [b], 'stopped, not playing; the other plays on');
|
||||
// The host loads it again from its checkpoint.
|
||||
checked((await W.load(code, [begin(a)]))[0]);
|
||||
assert.equal(W.has(code, a), true);
|
||||
});
|
||||
|
||||
test('a day with lists that are not lists is refused whole; the worker and its other sessions go on', async () => {
|
||||
const code = 'B4DDAY', nid = 'alon0001', other = 'BYSTD1', o = 'byst0009';
|
||||
checked((await E.load(code, [begin(nid)]))[0]);
|
||||
checked((await E.load(other, [begin(o)]))[0]);
|
||||
const w = E.stats().workers;
|
||||
for (const bad of [{ alone: {} }, { alone: 5 }, { nets: 'x' }]) await assert.rejects(within(E.day(code, { d: 1, nets: [nid], ...bad })), (e) => e.code === 'ERR', JSON.stringify(bad));
|
||||
assert.equal(checked(await within(E.day(code, { d: 1, nets: [nid], alone: [nid, 7] }))).nets[nid].day, 1);
|
||||
checked(await within(E.pull(other, o, {})));
|
||||
assert.deepEqual([E.stats().workers, E.has(other, o)], [w, true]);
|
||||
await E.unload(code); await E.unload(other);
|
||||
});
|
||||
|
||||
test('an exit counts against the session the worker was running, not one whose load waited behind it; own workers are capped', async (t) => {
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: ROOMY, maxOwn: 1 });
|
||||
t.after(() => W.close());
|
||||
// Twice: the hog's call runs for ever while another session's load waits behind it, and the worker dies.
|
||||
const hog = async (code, nid) => {
|
||||
for (let i = 0; i < 2; i++) {
|
||||
checked((await W.load(code, [begin(nid)]))[0]);
|
||||
const p = W.eval(code, nid, 'for(;;){}', 60000), q = W.load('J01NER', [begin('join0001')]);
|
||||
for (let k = 0; k < 300 && W.running(0) !== code; k++) await wait(10);
|
||||
assert.equal(W.running(0), code, 'the worker runs the hog');
|
||||
W.kill(0);
|
||||
await assert.rejects(p, (e) => e.code === 'EXIT');
|
||||
await assert.rejects(q, (e) => e.code === 'EXIT');
|
||||
}
|
||||
};
|
||||
await hog('H0G001', 'hogg0001');
|
||||
checked((await W.load('H0G001', [begin('hogg0001')]))[0]);
|
||||
checked((await W.load('J01NER', [begin('join0001')]))[0]);
|
||||
assert.deepEqual([W.dedicated('H0G001'), W.dedicated('J01NER')], [true, false], 'the hog has a worker of its own, the joiner none');
|
||||
// Another like it: no third worker (maxOwn 1), given up.
|
||||
await hog('H0G002', 'hogg0002');
|
||||
await assert.rejects(W.load('H0G002', [begin('hogg0002')]), (e) => e.code === 'GAVE_UP');
|
||||
assert.equal(W.stats().workers, 2);
|
||||
checked(await within(W.pull('J01NER', 'join0001', {}).catch(() => W.load('J01NER', [begin('join0001')]).then((r) => r[0]))));
|
||||
});
|
||||
|
||||
test('a worker that cannot start is not started again at once: after a few tries every call answers SIM_DOWN', async (t) => {
|
||||
const logs = [];
|
||||
const W = createEngine({ workers: 1, test: { ...TEST, startFail: true }, startBackoffMs: 10, log: (l, x) => logs.push(String(x)) });
|
||||
t.after(() => W.close());
|
||||
await assert.rejects(W.load('D0WN00', [begin('down0001')]), (e) => e.code === 'EXIT' || e.code === 'SIM_DOWN');
|
||||
for (let k = 0; k < 200 && !logs.some((x) => /server-run play is down/.test(x)); k++) await wait(50);
|
||||
await assert.rejects(W.load('D0WN00', [begin('down0001')]), (e) => e.code === 'SIM_DOWN');
|
||||
await assert.rejects(W.pull('D0WN00', 'down0001', {}), (e) => e.code === 'SIM_DOWN');
|
||||
await assert.rejects(W.day('D0WN00', { d: 1, nets: [] }), (e) => e.code === 'SIM_DOWN');
|
||||
await wait(300);
|
||||
assert.deepEqual([logs.filter((x) => /could not start/.test(x)).length, logs.filter((x) => /is down/.test(x)).length], [4, 1], 'five starts, then said once');
|
||||
});
|
||||
|
||||
test('the game is read once: a src/ that does not compile fails at start, and a worker started later runs the same game', async (t) => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-sim-src-'));
|
||||
t.after(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
||||
fs.cpSync(path.join(__dirname, '..', 'src'), path.join(tmp, 'src'), { recursive: true });
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: ROOMY, root: tmp });
|
||||
t.after(() => W.close());
|
||||
assert.equal(W.simId, E.simId, 'the same src/, the same build id');
|
||||
checked((await W.load('SAMEG4', [begin('same0001')]))[0]);
|
||||
// The checkout changes under a running engine (a pull before the restart), and its worker dies.
|
||||
fs.appendFileSync(path.join(tmp, 'src', 'game', '99-loop.js'), '\n;globalThis.__pulled=1;\n');
|
||||
W.kill(0);
|
||||
for (let k = 0; k < 200 && W.stats().realms; k++) await wait(10);
|
||||
checked((await W.load('SAMEG4', [begin('same0001')]))[0]);
|
||||
assert.equal((await W.eval('SAMEG4', 'same0001', 'return typeof globalThis.__pulled')).value, 'undefined', 'the game the engine names, not the one on disk');
|
||||
fs.appendFileSync(path.join(tmp, 'src', 'game', '99-loop.js'), '\n}}}(\n');
|
||||
assert.throws(() => createEngine({ workers: 1, root: tmp }), /does not compile/);
|
||||
});
|
||||
|
||||
test('a checkpoint whose route memory is damaged still loads; a save that is no server network does not', async () => {
|
||||
const code = 'RTDAMG', a = 'rtdm0001';
|
||||
const [L] = await E.load(code, [begin(a)]);
|
||||
checked(L);
|
||||
const s = L.saved.txt, net = (nid, env) => ({ nid, env: { uidN: L.saved.uidN, ...env }, lang: 'en', prefs: {} });
|
||||
const R = await E.load(code, [
|
||||
net('rtdm0002', { s, rt: { efg: { x: { g: [1, 2], v: [1] } } } }),
|
||||
net('rtdm0003', { s: JSON.stringify({ ...JSON.parse(s), mp: null }), rt: null }),
|
||||
net('rtdm0004', { s: JSON.stringify({ ...JSON.parse(s), mode: 'sandbox' }), rt: null }),
|
||||
]);
|
||||
R.forEach(checked);
|
||||
assert.equal(R[0].err, undefined, R[0].err);
|
||||
assert.match(R[1].err, /not a server network/);
|
||||
assert.match(R[2].err, /server networks are Normal games/);
|
||||
assert.equal(checked(await E.day(code, { d: 1, nets: ['rtdm0002'] })).nets.rtdm0002.day, 1);
|
||||
await E.unload(code);
|
||||
});
|
||||
|
||||
test('the fake engine fails as the engine does: the same edge calls, the same codes', async (t) => {
|
||||
const { createFakeEngine } = require('./lib/mp-sim-fake-engine');
|
||||
const lostR = [], lostF = [];
|
||||
const R = createEngine({ workers: 1, test: TEST, timeouts: ROOMY, onLost: (c, n, w) => lostR.push([c, n, w]) });
|
||||
const F = createFakeEngine({ onLost: (c, n, w) => lostF.push([c, n, w]) });
|
||||
t.after(() => R.close());
|
||||
const code = 'PAR1TY', a = 'pari0001', b = 'pari0002';
|
||||
const out = (p) => p.then((r) => (Array.isArray(r) ? r.map((x) => x.err || 'ok') : r && r.t === 'dayDone' ? Object.keys(r.nets) : 'ok'), (e) => 'rejected ' + e.code);
|
||||
const same = async (what, f) => { const x = await out(f(R)), y = await out(f(F)); assert.deepEqual(y, x, what); return x; };
|
||||
assert.equal(await same('an act with no realm', (X) => X.act(code, a, msg('buildPop', { city: 'ams' }))), 'rejected NO_REALM');
|
||||
await same('a load of nothing', (X) => X.load(code, []));
|
||||
await same('a network twice', (X) => X.load(code, [begin(a), begin(a)]));
|
||||
await same('neither a save nor a begin', (X) => X.load(code, [{ nid: a, env: { day: 5 }, lang: 'en', prefs: {} }]));
|
||||
await same('a day of a session that is not here', (X) => X.day('N0SVCH', { d: 1, nets: [a] }));
|
||||
await same('a load', (X) => X.load(code, [begin(a)]));
|
||||
await same('a day naming a network that is not loaded', (X) => X.day(code, { d: 1, nets: [a, b] }));
|
||||
await same('nets that is no list', (X) => X.day(code, { d: 2, nets: 'x' }));
|
||||
assert.deepEqual([R.has(code, a), F.has(code, a)], [true, true]);
|
||||
// A worker that dies: a session with nothing pending loses its realms all the same; its next call answers NO_REALM.
|
||||
R.kill(0); F.exit();
|
||||
for (let k = 0; k < 200 && !lostR.length; k++) await wait(10);
|
||||
assert.deepEqual(lostR, lostF);
|
||||
assert.deepEqual(lostR, [[code, [a], 'exit']]);
|
||||
assert.equal(await same('a call after the worker died', (X) => X.pull(code, a, {})), 'rejected NO_REALM');
|
||||
await R.close(); await F.close();
|
||||
await same('a load after close', (X) => X.load(code, [begin(a)]));
|
||||
assert.equal(await same('a pull after close', (X) => X.pull(code, a, {})), 'rejected CLOSED');
|
||||
});
|
||||
|
||||
test('a worker that exits rejects every call pending on it; the engine goes on with a new one', async () => {
|
||||
const W = createEngine({ workers: 1, test: TEST, timeouts: ROOMY });
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue