test(webui): drawer Stop review round: two Stops run at once in two drawers; coder's Stop the bus takes ends and repaints the page while ideas' still runs, and ideas keeps its running state; then ideas' is refused and each drawer keeps its own line (#1873, lane sp20-drawer-stop)
This commit was merged in pull request #1993.
This commit is contained in:
1 parent
b23ccdfc12
commit
e1642be760
1 file changed
+51
@@ -980,3 +980,54 @@ test('SP20: two Stops in two drawers each keep their own line and running state'
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Not stopped: instance-protected: ideas is protected from ending. Nothing changed.', 'Stop', false, false]);
|
||||
assert.deepEqual((await b.evaluate('window.__posts')).map(p => JSON.parse(p.body).instance), ['coder', 'ideas']);
|
||||
});
|
||||
|
||||
// SP20 review: two Stops run at once. One that ends, here the one the bus takes, which repaints the page,
|
||||
// does not end the other's running state or line, and each drawer keeps its own line after.
|
||||
test('SP20: two Stops running at once in two drawers each keep their own state', async t => {
|
||||
const data = D => { D.acme.instances.ideas = { definition: 'ideas', running: ['run-4'] }; };
|
||||
const { b, wait } = await setup(t, { hash: '#/agents?agent=acme%3Acoder', scripts: [FAST], data });
|
||||
const d = '[data-ws-drawer="acme:coder"]', i = '[data-ws-drawer="acme:ideas"]';
|
||||
const REQ = '0f0e0d0c-0b0a-4908-8706-050403020101';
|
||||
const state = x => `[${status(x)}, document.querySelector('${x} [data-drawer-stop]')?.firstChild.textContent, document.querySelector('${x} [data-drawer-stop]')?.disabled, document.querySelector('${x} [data-drawer-restart]')?.disabled]`;
|
||||
const ask = async x => {
|
||||
await b.evaluate(`document.querySelector('${x} [data-drawer-stop]').click()`);
|
||||
await wait(`document.querySelector('${x} [data-drawer-stop-yes]')`);
|
||||
await b.evaluate(`document.querySelector('${x} [data-drawer-stop-yes]').click()`);
|
||||
};
|
||||
const show = async (agent, x) => {
|
||||
await b.evaluate(`location.hash = "#/agents?agent=acme%3A${agent}"`);
|
||||
await wait(`${open(`acme:${agent}`)} && document.querySelector('${x} [data-drawer-stop]')`);
|
||||
};
|
||||
// Both terminates are held: coder's the bus takes, ideas' it refuses.
|
||||
await b.evaluate(`window.__answers.push(
|
||||
{ hold: new Promise(r => { window.__releaseCoder = r; }), status: 200, body: { sent: true, request: '${REQ}' } },
|
||||
{ hold: new Promise(r => { window.__releaseIdeas = r; }), status: 409, body: { error: 'instance-protected', message: 'instance-protected: ideas is protected from ending. Nothing changed.', sent: false } },
|
||||
{ status: 200, body: { request: '${REQ}', state: 'closed' } })`);
|
||||
await wait(`${open('acme:coder')} && document.querySelector('${d} [data-drawer-stop]')`);
|
||||
await ask(d);
|
||||
await wait('window.__posts.length === 1');
|
||||
await show('ideas', i);
|
||||
await ask(i);
|
||||
await wait('window.__posts.length === 2');
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Stopping ideas…', 'Stopping…', true, true]);
|
||||
// Coder's Stop ends while ideas' drawer is on screen; ideas' Stop still runs.
|
||||
await b.evaluate('window.__releaseCoder()');
|
||||
await wait('window.__posts.length === 3');
|
||||
await b.evaluate('new Promise(r => setTimeout(r, 300))');
|
||||
await wait(`${open('acme:ideas')} && document.querySelector('${i} [data-drawer-stop]')`);
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Stopping ideas…', 'Stopping…', true, true]);
|
||||
await show('coder', d);
|
||||
assert.deepEqual(await b.evaluate(state(d)), ['Stopped coder.', 'Stop', false, false]);
|
||||
// Ideas' Stop is refused; each drawer keeps its own line.
|
||||
await show('ideas', i);
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Stopping ideas…', 'Stopping…', true, true]);
|
||||
await b.evaluate('window.__releaseIdeas()');
|
||||
await wait(`/^Not stopped: /.test(${status(i)}) && ${usable(i)}`);
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Not stopped: instance-protected: ideas is protected from ending. Nothing changed.', 'Stop', false, false]);
|
||||
await show('coder', d);
|
||||
assert.deepEqual(await b.evaluate(state(d)), ['Stopped coder.', 'Stop', false, false]);
|
||||
assert.deepEqual((await b.evaluate('window.__posts')).map(p => [p.url, p.method]), [
|
||||
['/api/orgs/acme/agent/terminate', 'POST'], ['/api/orgs/acme/agent/terminate', 'POST'], [`/api/orgs/acme/agent/request?id=${REQ}`, 'GET']]);
|
||||
assert.deepEqual((await b.evaluate('window.__posts')).slice(0, 2).map(p => JSON.parse(p.body).instance), ['coder', 'ideas']);
|
||||
assert.equal(await b.evaluate('window.__answers.length'), 0, 'every queued answer was asked for');
|
||||
});
|
||||
Reference in new issue
Block a user