From 5e78c956d96b2cd40c373cf7e5724cd3c39739eb Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Fri, 22 Mar 2024 11:50:42 -0700 Subject: [PATCH 1/3] test(daemon): Refactor test.endo.js Progresses #2125 Extracts locator setup into utility function and adds test teardown that will always run, except in cases of multiple locators being created. The multiple locator case will be handled in a follow-up. This fully resolves #2125, except in cases where tests that create multiple locators fail. --- packages/daemon/index.js | 9 +- packages/daemon/src/formula-type.js | 2 + packages/daemon/test/test-endo.js | 359 +++++++--------------------- 3 files changed, 96 insertions(+), 274 deletions(-) diff --git a/packages/daemon/index.js b/packages/daemon/index.js index 7ff05b36ad..5ce14b6c94 100644 --- a/packages/daemon/index.js +++ b/packages/daemon/index.js @@ -149,15 +149,14 @@ export const clean = async (locator = defaultLocator) => { } }; -export const restart = async (locator = defaultLocator) => { +export const stop = async (locator = defaultLocator) => { await terminate(locator).catch(() => {}); await clean(locator); - return start(locator); }; -export const stop = async (locator = defaultLocator) => { - await terminate(locator).catch(() => {}); - await clean(locator); +export const restart = async (locator = defaultLocator) => { + await stop(locator); + return start(locator); }; export const purge = async (locator = defaultLocator) => { diff --git a/packages/daemon/src/formula-type.js b/packages/daemon/src/formula-type.js index 44dcbe9d17..78e7dc9c62 100644 --- a/packages/daemon/src/formula-type.js +++ b/packages/daemon/src/formula-type.js @@ -1,3 +1,5 @@ +// @ts-check + const { quote: q } = assert; // Note: Alphabetically sorted diff --git a/packages/daemon/test/test-endo.js b/packages/daemon/test/test-endo.js index faecb05fb7..3ac35dfc59 100644 --- a/packages/daemon/test/test-endo.js +++ b/packages/daemon/test/test-endo.js @@ -17,7 +17,6 @@ import { start, stop, restart, - clean, purge, makeEndoClient, makeReaderRef, @@ -118,15 +117,54 @@ const doMakeBundle = async (host, filePath, callback) => { return result; }; -test('lifecycle', async t => { +let locatorPathId = 0; + +/** @param {string} testTitle */ +const getLocatorSubDirectory = testTitle => { + const defaultPath = testTitle.replace(/\s/giu, '-').replace(/[^\w-]/giu, ''); + + if (defaultPath.length <= 30) { + return defaultPath; + } + + // Truncate the subdirectory name to 30 characters in an attempt to respect + // the maximum Unix domain socket path length. + // With our apologies to John Jacob Jingleheimerschmidt, for whom this may + // not be enough. + const locatorSubDirectory = `${defaultPath.slice(0, 25)}$${String( + locatorPathId, + ).padStart(4, '0')}`; + + locatorPathId += 1; + + return locatorSubDirectory; +}; + +/** @param {import('ava').ExecutionContext} t */ +const prepareLocator = async t => { const { reject: cancel, promise: cancelled } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'lifecycle'); + const locator = makeLocator('tmp', getLocatorSubDirectory(t.title)); await stop(locator).catch(() => {}); await purge(locator); - await clean(locator); await start(locator); + + const context = { cancel, cancelled, locator }; + t.context = context; + return { ...context }; +}; + +test.afterEach.always(async t => { + const { locator, cancel, cancelled } = + /** @type {Awaited>} */ (t.context); + + cancel(Error('teardown')); + await Promise.allSettled([cancelled, stop(locator)]); +}); + +test('lifecycle', async t => { + const { cancel, cancelled, locator } = await prepareLocator(t); + await stop(locator); await restart(locator); @@ -142,18 +180,11 @@ test('lifecycle', async t => { cancel(new Error('Cancelled')); await closed.catch(() => {}); - await stop(locator); t.pass(); }); test('spawn and evaluate', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'spawn-eval'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -165,18 +196,10 @@ test('spawn and evaluate', async t => { await E(host).provideWorker('w1'); const ten = await E(host).evaluate('w1', '10', [], []); t.is(ten, 10); - - await stop(locator); }); test('anonymous spawn and evaluate', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'spawn-eval-anon'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -187,18 +210,10 @@ test('anonymous spawn and evaluate', async t => { const host = E(bootstrap).host(); const ten = await E(host).evaluate('MAIN', '10', [], []); t.is(ten, 10); - - await stop(locator); }); test('anonymous spawn and evaluate with new worker', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'spawn-eval-anon-new-worker'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -209,19 +224,11 @@ test('anonymous spawn and evaluate with new worker', async t => { const host = E(bootstrap).host(); const ten = await E(host).evaluate('NEW', '10', [], []); t.is(ten, 10); - - await stop(locator); }); // Regression test for https://github.com/endojs/endo/issues/2147 test('spawning a worker does not overwrite existing non-worker name', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'spawn-eval-name-reuse'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -240,18 +247,10 @@ test('spawning a worker does not overwrite existing non-worker name', async t => message: 'Cannot deliver "evaluate" to target; typeof target is "undefined"', }); - - await stop(locator); }); test('persist spawn and evaluation', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'persist-spawn-eval'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); { const { getBootstrap } = await makeEndoClient( @@ -297,18 +296,10 @@ test('persist spawn and evaluation', async t => { const retwenty = await E(host).lookup('twenty'); t.is(20, retwenty); } - - await stop(locator); }); test('store without name', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'store-without-name'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -321,18 +312,10 @@ test('store without name', async t => { const readable = await E(host).store(readerRef); const actualText = await E(readable).text(); t.is(actualText, 'hello\n'); - - await stop(locator); }); test('store with name', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'store-with-name'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); { const { getBootstrap } = await makeEndoClient( @@ -360,18 +343,10 @@ test('store with name', async t => { const actualText = await E(readable).text(); t.is(actualText, 'hello\n'); } - - await stop(locator); }); test('closure state lost by restart', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'restart-closures'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); { const { getBootstrap } = await makeEndoClient( @@ -460,18 +435,10 @@ test('closure state lost by restart', async t => { t.is(two, 2); t.is(three, 3); } - - await stop(locator); }); test('persist unconfined services and their requests', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'make-unconfined'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const responderFinished = (async () => { const { promise: followerCancelled, reject: cancelFollower } = @@ -545,18 +512,10 @@ test('persist unconfined services and their requests', async t => { const number = await E(answer).value(); t.is(number, 42); } - - await stop(locator); }); test('persist confined services and their requests', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'make-bundle'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const responderFinished = (async () => { const { promise: followerCancelled, reject: cancelFollower } = @@ -631,17 +590,10 @@ test('persist confined services and their requests', async t => { const number = await E(answer).value(); t.is(number, 42); } - - await stop(locator); }); test('guest facet receives a message for host', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'guest-sends-host'); - - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -687,18 +639,10 @@ test('guest facet receives a message for host', async t => { { type: 'package', who: 'SELF', dest: 'HOST' }, ], ); - - await stop(locator); }); test('direct cancellation', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-direct'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -772,13 +716,7 @@ test('direct cancellation', async t => { // Regression test 1 for https://github.com/endojs/endo/issues/2074 test('indirect cancellation via worker', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-indirect-worker'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -853,13 +791,7 @@ test('indirect cancellation via worker', async t => { // Regression test 2 for https://github.com/endojs/endo/issues/2074 test.failing('indirect cancellation via caplet', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-indirect-caplet'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -907,13 +839,7 @@ test.failing('indirect cancellation via caplet', async t => { }); test('cancel because of requested capability', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-via-request'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -995,13 +921,7 @@ test('cancel because of requested capability', async t => { }); test('unconfined service can respond to cancellation', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-unconfined-response'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1032,13 +952,7 @@ test('unconfined service can respond to cancellation', async t => { }); test('confined service can respond to cancellation', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'cancellation-confined-response'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1065,13 +979,7 @@ test('confined service can respond to cancellation', async t => { }); test('make a host', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'make-host'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1084,18 +992,10 @@ test('make a host', async t => { await E(host2).provideWorker('w1'); const ten = await E(host2).evaluate('w1', '10', [], []); t.is(ten, 10); - - await stop(locator); }); test('name and reuse inspector', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'inspector-reuse'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1125,19 +1025,11 @@ test('name and reuse inspector', async t => { ['inspector'], ); t.regex(String(worker), /Alleged: EndoWorker/u); - - await stop(locator); }); // Regression test for https://github.com/endojs/endo/issues/2021 test.failing('eval-mediated worker name', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'eval-worker-name'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1182,18 +1074,10 @@ test.failing('eval-mediated worker name', async t => { ), 2, ); - - await stop(locator); }); test('lookup with single petname', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'lookup-single-petname'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1213,18 +1097,10 @@ test('lookup with single petname', async t => { ['SELF'], ); t.is(resolvedValue, 10); - - await stop(locator); }); test('lookup with petname path (inspector)', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'lookup-petname-path-inspector'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1242,18 +1118,10 @@ test('lookup with petname path (inspector)', async t => { ['SELF'], ); t.is(resolvedValue, '10'); - - await stop(locator); }); test('lookup with petname path (caplet with lookup method)', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'lookup-petname-path-caplet'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1273,18 +1141,10 @@ test('lookup with petname path (caplet with lookup method)', async t => { ['SELF'], ); t.is(resolvedValue, 'Looked up: name'); - - await stop(locator); }); test('lookup with petname path (value has no lookup method)', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'lookup-petname-path-no-method'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1304,18 +1164,10 @@ test('lookup with petname path (value has no lookup method)', async t => { ), { message: 'target has no method "lookup", has []' }, ); - - await stop(locator); }); test('evaluate name resolved by lookup path', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'name-resolved-by-lookup-path'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1334,18 +1186,10 @@ test('evaluate name resolved by lookup path', async t => { [['INFO', 'ten', 'source']], ); t.is(resolvedValue, '10'); - - await stop(locator); }); test('list special names', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'list-names'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1372,13 +1216,7 @@ test('list special names', async t => { }); test('guest cannot access host methods', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - - const locator = makeLocator('tmp', 'guest-cannot-host'); - - await start(locator); - t.teardown(() => stop(locator)); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1396,14 +1234,8 @@ test('guest cannot access host methods', async t => { t.is(revealedTarget, undefined); }); -test('read unknown nodeId', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'read-unknown-nodeid'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); +test('read unknown node id', async t => { + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1421,22 +1253,27 @@ test('read unknown nodeId', async t => { number, }); await E(host).write(['abc'], id); + // observe reification failure - t.throwsAsync(() => E(host).lookup('abc'), { + await t.throwsAsync(() => E(host).lookup('abc'), { message: /No peer found for node identifier /u, }); - - await stop(locator); }); test('read remote value', async t => { const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); const locatorA = makeLocator('tmp', 'read-remote-value-a'); const locatorB = makeLocator('tmp', 'read-remote-value-b'); const hostA = await makeHostWithTestNetwork(locatorA, cancelled); const hostB = await makeHostWithTestNetwork(locatorB, cancelled); + // Set up custom teardown due to multiple locators + t.context = { cancel, cancelled, locator: {} }; + t.teardown(async () => { + cancel(new Error('teardown')); + await Promise.allSettled([cancelled, stop(locatorA), stop(locatorB)]); + }); + // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); await E(hostB).addPeerInfo(await E(hostA).getPeerInfo()); @@ -1450,19 +1287,10 @@ test('read remote value', async t => { const hostAValue = await E(hostA).lookup('greetings'); t.is(hostAValue, 'hello, world!'); - - await stop(locatorA); - await stop(locatorB); }); test('locate local value', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'locate-local-value'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); const { getBootstrap } = await makeEndoClient( 'client', @@ -1477,18 +1305,10 @@ test('locate local value', async t => { const tenLocator = await E(host).locate('ten'); const parsedLocator = parseLocator(tenLocator); t.is(parsedLocator.formulaType, 'eval'); - - await stop(locator); }); test('locate local persisted value', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); - const locator = makeLocator('tmp', 'locate-local-persisted-value'); - - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); + const { cancelled, locator } = await prepareLocator(t); { const { getBootstrap } = await makeEndoClient( @@ -1516,18 +1336,22 @@ test('locate local persisted value', async t => { const parsedLocator = parseLocator(tenLocator); t.is(parsedLocator.formulaType, 'eval'); } - - await stop(locator); }); test('locate remote value', async t => { const { promise: cancelled, reject: cancel } = makePromiseKit(); - t.teardown(() => cancel(Error('teardown'))); const locatorA = makeLocator('tmp', 'locate-remote-value-a'); const locatorB = makeLocator('tmp', 'locate-remote-value-b'); const hostA = await makeHostWithTestNetwork(locatorA, cancelled); const hostB = await makeHostWithTestNetwork(locatorB, cancelled); + // Set up custom teardown due to multiple locators + t.context = { cancel, cancelled, locator: {} }; + t.teardown(async () => { + cancel(new Error('teardown')); + await Promise.allSettled([cancelled, stop(locatorA), stop(locatorB)]); + }); + // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); await E(hostB).addPeerInfo(await E(hostA).getPeerInfo()); @@ -1542,7 +1366,4 @@ test('locate remote value', async t => { const greetingsLocator = await E(hostA).locate('greetings'); const parsedGreetingsLocator = parseLocator(greetingsLocator); t.is(parsedGreetingsLocator.formulaType, 'remote'); - - await stop(locatorA); - await stop(locatorB); }); From fa6067130677c3516d06781a60f86991b1be2a57 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Fri, 22 Mar 2024 15:52:29 -0700 Subject: [PATCH 2/3] test(daemon): Adapt prepareLocator and teardown for multiple locators per test --- packages/daemon/test/test-endo.js | 84 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/packages/daemon/test/test-endo.js b/packages/daemon/test/test-endo.js index 3ac35dfc59..62eccac0c6 100644 --- a/packages/daemon/test/test-endo.js +++ b/packages/daemon/test/test-endo.js @@ -119,47 +119,59 @@ const doMakeBundle = async (host, filePath, callback) => { let locatorPathId = 0; -/** @param {string} testTitle */ -const getLocatorSubDirectory = testTitle => { +/** + * @param {string} testTitle - The title of the current test. + * @param {number} locatorNumber - The number of the current locator. If this + * is the n:th locator created for the current test, the locator number is n. + */ +const getLocatorSubDirectory = (testTitle, locatorNumber) => { const defaultPath = testTitle.replace(/\s/giu, '-').replace(/[^\w-]/giu, ''); - if (defaultPath.length <= 30) { - return defaultPath; - } - - // Truncate the subdirectory name to 30 characters in an attempt to respect + // We truncate the subdirectory name to 30 characters in an attempt to respect // the maximum Unix domain socket path length. // With our apologies to John Jacob Jingleheimerschmidt, for whom this may // not be enough. - const locatorSubDirectory = `${defaultPath.slice(0, 25)}$${String( - locatorPathId, - ).padStart(4, '0')}`; + const basePath = + defaultPath.length <= 22 ? defaultPath : defaultPath.slice(0, 22); + const testId = String(locatorPathId).padStart(4, '0'); + const locatorId = String(locatorNumber).padStart(2, '0'); + const locatorSubDirectory = `${basePath}#${testId}-${locatorId}`; locatorPathId += 1; return locatorSubDirectory; }; -/** @param {import('ava').ExecutionContext} t */ +/** @param {import('ava').ExecutionContext} t */ const prepareLocator = async t => { const { reject: cancel, promise: cancelled } = makePromiseKit(); - const locator = makeLocator('tmp', getLocatorSubDirectory(t.title)); + const locator = makeLocator( + 'tmp', + getLocatorSubDirectory(t.title, t.context.length), + ); await stop(locator).catch(() => {}); await purge(locator); await start(locator); - const context = { cancel, cancelled, locator }; - t.context = context; - return { ...context }; + const contextObj = { cancel, cancelled, locator }; + t.context.push(contextObj); + return { ...contextObj }; }; -test.afterEach.always(async t => { - const { locator, cancel, cancelled } = - /** @type {Awaited>} */ (t.context); +test.beforeEach(t => { + t.context = []; +}); - cancel(Error('teardown')); - await Promise.allSettled([cancelled, stop(locator)]); +test.afterEach.always(async t => { + await Promise.allSettled( + /** @type {Awaited>[]} */ (t.context).flatMap( + ({ cancel, cancelled, locator }) => { + cancel(Error('teardown')); + return [cancelled, stop(locator)]; + }, + ), + ); }); test('lifecycle', async t => { @@ -1261,18 +1273,10 @@ test('read unknown node id', async t => { }); test('read remote value', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - const locatorA = makeLocator('tmp', 'read-remote-value-a'); - const locatorB = makeLocator('tmp', 'read-remote-value-b'); - const hostA = await makeHostWithTestNetwork(locatorA, cancelled); - const hostB = await makeHostWithTestNetwork(locatorB, cancelled); - - // Set up custom teardown due to multiple locators - t.context = { cancel, cancelled, locator: {} }; - t.teardown(async () => { - cancel(new Error('teardown')); - await Promise.allSettled([cancelled, stop(locatorA), stop(locatorB)]); - }); + const { locator: locatorA, cancelled: cancelledA } = await prepareLocator(t); + const { locator: locatorB, cancelled: cancelledB } = await prepareLocator(t); + const hostA = await makeHostWithTestNetwork(locatorA, cancelledA); + const hostB = await makeHostWithTestNetwork(locatorB, cancelledB); // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); @@ -1339,18 +1343,10 @@ test('locate local persisted value', async t => { }); test('locate remote value', async t => { - const { promise: cancelled, reject: cancel } = makePromiseKit(); - const locatorA = makeLocator('tmp', 'locate-remote-value-a'); - const locatorB = makeLocator('tmp', 'locate-remote-value-b'); - const hostA = await makeHostWithTestNetwork(locatorA, cancelled); - const hostB = await makeHostWithTestNetwork(locatorB, cancelled); - - // Set up custom teardown due to multiple locators - t.context = { cancel, cancelled, locator: {} }; - t.teardown(async () => { - cancel(new Error('teardown')); - await Promise.allSettled([cancelled, stop(locatorA), stop(locatorB)]); - }); + const { locator: locatorA, cancelled: cancelledA } = await prepareLocator(t); + const { locator: locatorB, cancelled: cancelledB } = await prepareLocator(t); + const hostA = await makeHostWithTestNetwork(locatorA, cancelledA); + const hostB = await makeHostWithTestNetwork(locatorB, cancelledB); // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); From c5743337635bd2955a0de83bc826e95619a616fe Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Fri, 22 Mar 2024 16:00:29 -0700 Subject: [PATCH 3/3] test(daemon): Add makeHost utility --- packages/daemon/test/test-endo.js | 335 +++++------------------------- 1 file changed, 54 insertions(+), 281 deletions(-) diff --git a/packages/daemon/test/test-endo.js b/packages/daemon/test/test-endo.js index 62eccac0c6..d54ff63906 100644 --- a/packages/daemon/test/test-endo.js +++ b/packages/daemon/test/test-endo.js @@ -50,19 +50,23 @@ const makeLocator = (...root) => { * @param {ReturnType} locator * @param {Promise} cancelled */ -const makeHostWithTestNetwork = async (locator, cancelled) => { - await stop(locator).catch(() => {}); - await purge(locator); - await start(locator); - +const makeHost = async (locator, cancelled) => { const { getBootstrap } = await makeEndoClient( 'client', locator.sockPath, cancelled, ); const bootstrap = getBootstrap(); + return { host: E(bootstrap).host() }; +}; + +/** + * @param {ReturnType} locator + * @param {Promise} cancelled + */ +const makeHostWithTestNetwork = async (locator, cancelled) => { + const { host } = await makeHost(locator, cancelled); - const host = E(bootstrap).host(); // Install test network const servicePath = path.join(dirname, 'src', 'networks', 'tcp-netstring.js'); const serviceLocation = url.pathToFileURL(servicePath).href; @@ -124,7 +128,7 @@ let locatorPathId = 0; * @param {number} locatorNumber - The number of the current locator. If this * is the n:th locator created for the current test, the locator number is n. */ -const getLocatorSubDirectory = (testTitle, locatorNumber) => { +const getLocatorDirectoryName = (testTitle, locatorNumber) => { const defaultPath = testTitle.replace(/\s/giu, '-').replace(/[^\w-]/giu, ''); // We truncate the subdirectory name to 30 characters in an attempt to respect @@ -147,7 +151,7 @@ const prepareLocator = async t => { const { reject: cancel, promise: cancelled } = makePromiseKit(); const locator = makeLocator( 'tmp', - getLocatorSubDirectory(t.title, t.context.length), + getLocatorDirectoryName(t.title, t.context.length), ); await stop(locator).catch(() => {}); @@ -197,14 +201,8 @@ test('lifecycle', async t => { test('spawn and evaluate', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('w1'); const ten = await E(host).evaluate('w1', '10', [], []); t.is(ten, 10); @@ -212,28 +210,16 @@ test('spawn and evaluate', async t => { test('anonymous spawn and evaluate', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const ten = await E(host).evaluate('MAIN', '10', [], []); t.is(ten, 10); }); test('anonymous spawn and evaluate with new worker', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const ten = await E(host).evaluate('NEW', '10', [], []); t.is(ten, 10); }); @@ -241,14 +227,8 @@ test('anonymous spawn and evaluate with new worker', async t => { // Regression test for https://github.com/endojs/endo/issues/2147 test('spawning a worker does not overwrite existing non-worker name', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const foo = await E(host).evaluate('MAIN', '10', [], [], 'foo'); t.is(foo, 10); @@ -265,13 +245,7 @@ test('persist spawn and evaluation', async t => { const { cancelled, locator } = await prepareLocator(t); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).provideWorker('w1'); @@ -296,14 +270,7 @@ test('persist spawn and evaluation', async t => { await restart(locator); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const retwenty = await E(host).lookup('twenty'); t.is(20, retwenty); @@ -312,14 +279,8 @@ test('persist spawn and evaluation', async t => { test('store without name', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); const readable = await E(host).store(readerRef); const actualText = await E(readable).text(); @@ -330,13 +291,7 @@ test('store with name', async t => { const { cancelled, locator } = await prepareLocator(t); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); const readable = await E(host).store(readerRef, 'hello-text'); const actualText = await E(readable).text(); @@ -344,13 +299,7 @@ test('store with name', async t => { } { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const readable = await E(host).lookup('hello-text'); const actualText = await E(readable).text(); t.is(actualText, 'hello\n'); @@ -361,13 +310,7 @@ test('closure state lost by restart', async t => { const { cancelled, locator } = await prepareLocator(t); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).provideWorker('w1'); await E(host).evaluate( @@ -417,13 +360,7 @@ test('closure state lost by restart', async t => { await restart(locator); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).lookup('w1'); const one = await E(host).evaluate( 'w1', @@ -456,14 +393,9 @@ test('persist unconfined services and their requests', async t => { const { promise: followerCancelled, reject: cancelFollower } = makePromiseKit(); cancelled.catch(cancelFollower); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - followerCancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, followerCancelled); await E(host).provideWorker('user-worker'); + await E(host).evaluate( 'user-worker', ` @@ -483,15 +415,10 @@ test('persist unconfined services and their requests', async t => { })(); const requesterFinished = (async () => { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).provideWorker('w1'); await E(host).provideGuest('o1'); + const servicePath = path.join(dirname, 'test', 'service.js'); const serviceLocation = url.pathToFileURL(servicePath).href; await E(host).makeUnconfined('w1', serviceLocation, 'o1', 's1'); @@ -513,13 +440,7 @@ test('persist unconfined services and their requests', async t => { await restart(locator); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const answer = await E(host).lookup('answer'); const number = await E(answer).value(); t.is(number, 42); @@ -533,14 +454,9 @@ test('persist confined services and their requests', async t => { const { promise: followerCancelled, reject: cancelFollower } = makePromiseKit(); cancelled.catch(cancelFollower); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - followerCancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, followerCancelled); await E(host).provideWorker('user-worker'); + await E(host).evaluate( 'user-worker', ` @@ -560,15 +476,10 @@ test('persist confined services and their requests', async t => { })(); const requesterFinished = (async () => { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).provideWorker('w1'); await E(host).provideGuest('o1'); + const servicePath = path.join(dirname, 'test', 'service.js'); await doMakeBundle(host, servicePath, bundleName => E(host).makeBundle('w1', bundleName, 'o1', 's1'), @@ -591,13 +502,7 @@ test('persist confined services and their requests', async t => { await restart(locator); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const answer = await E(host).lookup('answer'); const number = await E(answer).value(); t.is(number, 42); @@ -606,14 +511,8 @@ test('persist confined services and their requests', async t => { test('guest facet receives a message for host', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const guest = E(host).provideGuest('guest'); await E(host).provideWorker('worker'); await E(host).evaluate('worker', '10', [], [], 'ten1'); @@ -655,14 +554,8 @@ test('guest facet receives a message for host', async t => { test('direct cancellation', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -729,14 +622,8 @@ test('direct cancellation', async t => { // Regression test 1 for https://github.com/endojs/endo/issues/2074 test('indirect cancellation via worker', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -804,14 +691,7 @@ test('indirect cancellation via worker', async t => { // Regression test 2 for https://github.com/endojs/endo/issues/2074 test.failing('indirect cancellation via caplet', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).provideWorker('w1'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -852,14 +732,8 @@ test.failing('indirect cancellation via caplet', async t => { test('cancel because of requested capability', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); await E(host).provideGuest('guest'); @@ -934,14 +808,8 @@ test('cancel because of requested capability', async t => { test('unconfined service can respond to cancellation', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const capletPath = path.join(dirname, 'test', 'context-consumer.js'); @@ -965,14 +833,8 @@ test('unconfined service can respond to cancellation', async t => { test('confined service can respond to cancellation', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const capletPath = path.join(dirname, 'test', 'context-consumer.js'); @@ -992,14 +854,8 @@ test('confined service can respond to cancellation', async t => { test('make a host', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const host2 = E(host).provideHost('fellow-host'); await E(host2).provideWorker('w1'); const ten = await E(host2).evaluate('w1', '10', [], []); @@ -1008,14 +864,8 @@ test('make a host', async t => { test('name and reuse inspector', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -1042,14 +892,8 @@ test('name and reuse inspector', async t => { // Regression test for https://github.com/endojs/endo/issues/2021 test.failing('eval-mediated worker name', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideWorker('worker'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -1090,14 +934,8 @@ test.failing('eval-mediated worker name', async t => { test('lookup with single petname', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).provideGuest('guest'); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); t.is(ten, 10); @@ -1113,14 +951,8 @@ test('lookup with single petname', async t => { test('lookup with petname path (inspector)', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); await E(host).evaluate('MAIN', '10', [], [], 'ten'); const resolvedValue = await E(host).evaluate( @@ -1134,14 +966,7 @@ test('lookup with petname path (inspector)', async t => { test('lookup with petname path (caplet with lookup method)', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const lookupPath = path.join(dirname, 'test', 'lookup.js'); await E(host).makeUnconfined('MAIN', lookupPath, 'NONE', 'lookup'); @@ -1157,14 +982,7 @@ test('lookup with petname path (caplet with lookup method)', async t => { test('lookup with petname path (value has no lookup method)', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).evaluate('MAIN', '10', [], [], 'ten'); await t.throwsAsync( @@ -1180,14 +998,7 @@ test('lookup with petname path (value has no lookup method)', async t => { test('evaluate name resolved by lookup path', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); await E(host).evaluate('MAIN', '10', [], [], 'ten'); @@ -1202,14 +1013,7 @@ test('evaluate name resolved by lookup path', async t => { test('list special names', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); await E(host).store(readerRef, 'hello-text'); @@ -1229,14 +1033,8 @@ test('list special names', async t => { test('guest cannot access host methods', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const guest = E(host).provideGuest('guest'); const guestsHost = E(guest).lookup('HOST'); await t.throwsAsync(() => E(guestsHost).lookup('SELF'), { @@ -1248,14 +1046,7 @@ test('guest cannot access host methods', async t => { test('read unknown node id', async t => { const { cancelled, locator } = await prepareLocator(t); - - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); // write a bogus value for a bogus nodeId const node = await cryptoPowers.randomHex512(); @@ -1295,14 +1086,8 @@ test('read remote value', async t => { test('locate local value', async t => { const { cancelled, locator } = await prepareLocator(t); + const { host } = await makeHost(locator, cancelled); - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); t.is(ten, 10); @@ -1315,13 +1100,7 @@ test('locate local persisted value', async t => { const { cancelled, locator } = await prepareLocator(t); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); t.is(ten, 10); } @@ -1329,13 +1108,7 @@ test('locate local persisted value', async t => { await restart(locator); { - const { getBootstrap } = await makeEndoClient( - 'client', - locator.sockPath, - cancelled, - ); - const bootstrap = getBootstrap(); - const host = E(bootstrap).host(); + const { host } = await makeHost(locator, cancelled); const tenLocator = await E(host).locate('ten'); const parsedLocator = parseLocator(tenLocator); t.is(parsedLocator.formulaType, 'eval');