diff --git a/packages/async-flow/test/_utils.js b/packages/async-flow/test/_utils.js new file mode 100644 index 000000000000..c3005a36b4f0 --- /dev/null +++ b/packages/async-flow/test/_utils.js @@ -0,0 +1,21 @@ +import { prepareAsyncFlowTools } from '../src/async-flow.js'; + +/** + * @param {*} t + * @param {import('@agoric/base-zone').Zone} zone + * @param {Parameters[1]} powers + * @returns + */ +export const prepareTestAsyncFlowTools = (t, zone, powers) => { + const { asyncFlow: rawAsyncFlow, ...rest } = prepareAsyncFlowTools( + zone, + powers, + ); + /** @type {typeof rawAsyncFlow} */ + const asyncFlow = (zone, name, guestFunc, opts) => { + const { panicHandler = e => t.log('Handled panic', e) } = opts || {}; + return rawAsyncFlow(zone, name, guestFunc, { panicHandler, ...opts }); + }; + return harden({ asyncFlow, ...rest }); +}; +harden(prepareTestAsyncFlowTools); diff --git a/packages/async-flow/test/async-flow-crank.test.js b/packages/async-flow/test/async-flow-crank.test.js index db2452057472..39dfbb7e7195 100644 --- a/packages/async-flow/test/async-flow-crank.test.js +++ b/packages/async-flow/test/async-flow-crank.test.js @@ -14,12 +14,10 @@ import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { prepareVowTools } from '@agoric/vow'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareAsyncFlowTools } from '../src/async-flow.js'; +import { prepareTestAsyncFlowTools } from './_utils.js'; /** - * @import {PromiseKit} from '@endo/promise-kit' * @import {Zone} from '@agoric/base-zone' - * @import {Ephemera} from './types.js'; */ const neverSettlesP = new Promise(() => {}); @@ -30,7 +28,7 @@ const neverSettlesP = new Promise(() => {}); */ const testPlay1 = async (t, zone) => { const vowTools = prepareVowTools(zone); - const { asyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); @@ -48,7 +46,7 @@ const testPlay1 = async (t, zone) => { */ const testPlay2 = async (t, zone) => { const vowTools = prepareVowTools(zone); - const { asyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); @@ -63,7 +61,7 @@ const testPlay2 = async (t, zone) => { */ const testPlay3 = async (t, zone) => { const vowTools = prepareVowTools(zone); - const { asyncFlow, allWokenP } = prepareAsyncFlowTools(zone, { + const { asyncFlow, allWokenP } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); diff --git a/packages/async-flow/test/async-flow-early-completion.test.js b/packages/async-flow/test/async-flow-early-completion.test.js index c31fb85dd6f7..61b2785f6514 100644 --- a/packages/async-flow/test/async-flow-early-completion.test.js +++ b/packages/async-flow/test/async-flow-early-completion.test.js @@ -15,7 +15,7 @@ import { isVow } from '@agoric/vow/src/vow-utils.js'; import { prepareVowTools } from '@agoric/vow'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareAsyncFlowTools } from '../src/async-flow.js'; +import { prepareTestAsyncFlowTools } from './_utils.js'; /** * @import {Zone} from '@agoric/base-zone'; @@ -59,7 +59,7 @@ const firstLogLen = 7; const testFirstPlay = async (t, zone) => { t.log('firstPlay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); const makeOrchestra = prepareOrchestra(zone); @@ -141,7 +141,7 @@ const testFirstPlay = async (t, zone) => { const testBadShortReplay = async (t, zone, rejection) => { t.log('badShortReplay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); prepareOrchestra(zone); diff --git a/packages/async-flow/test/async-flow-no-this.js b/packages/async-flow/test/async-flow-no-this.js index 12e2e0ba83e7..203717a726bf 100644 --- a/packages/async-flow/test/async-flow-no-this.js +++ b/packages/async-flow/test/async-flow-no-this.js @@ -7,12 +7,10 @@ import { makeHeapZone } from '@agoric/zone/heap.js'; import { makeVirtualZone } from '@agoric/zone/virtual.js'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareAsyncFlowTools } from '../src/async-flow.js'; +import { prepareTestAsyncFlowTools } from './_utils.js'; /** * @import {Zone} from '@agoric/base-zone'; - * @import {Vow, VowTools} from '@agoric/vow' - * @import {AsyncFlow} from '../src/async-flow.js' */ const { apply } = Reflect; @@ -23,7 +21,7 @@ const { apply } = Reflect; */ const testPlay = async (t, zone) => { const vowTools = prepareVowTools(zone); - const { asyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); diff --git a/packages/async-flow/test/async-flow.test.js b/packages/async-flow/test/async-flow.test.js index ed281cc9bf59..c81428a48f8c 100644 --- a/packages/async-flow/test/async-flow.test.js +++ b/packages/async-flow/test/async-flow.test.js @@ -17,7 +17,7 @@ import { makeHeapZone } from '@agoric/zone/heap.js'; import { makeVirtualZone } from '@agoric/zone/virtual.js'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareAsyncFlowTools } from '../src/async-flow.js'; +import { prepareTestAsyncFlowTools } from './_utils.js'; /** * @import {AsyncFlow} from '../src/async-flow.js' @@ -62,7 +62,7 @@ const firstLogLen = 7; const testFirstPlay = async (t, zone) => { t.log('firstPlay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); const makeOrchestra = prepareOrchestra(zone); @@ -139,7 +139,7 @@ const testFirstPlay = async (t, zone) => { const testBadReplay = async (t, zone) => { t.log('badReplay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); prepareOrchestra(zone); @@ -206,7 +206,7 @@ const testBadReplay = async (t, zone) => { const testGoodReplay = async (t, zone) => { t.log('goodReplay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); prepareOrchestra(zone, 2); // Note change in new behavior @@ -310,7 +310,7 @@ const testGoodReplay = async (t, zone) => { const testAfterPlay = async (t, zone) => { t.log('testAfterPlay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); prepareOrchestra(zone); diff --git a/packages/async-flow/test/bad-host.test.js b/packages/async-flow/test/bad-host.test.js index a7d3bb8893cc..b72c6d49b621 100644 --- a/packages/async-flow/test/bad-host.test.js +++ b/packages/async-flow/test/bad-host.test.js @@ -15,7 +15,7 @@ import { makeHeapZone } from '@agoric/zone/heap.js'; import { makeVirtualZone } from '@agoric/zone/virtual.js'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareAsyncFlowTools } from '../src/async-flow.js'; +import { prepareTestAsyncFlowTools } from './_utils.js'; /** * @import {PromiseKit} from '@endo/promise-kit' @@ -51,7 +51,7 @@ const prepareBadHost = zone => const testBadHostFirstPlay = async (t, zone) => { t.log('badHost firstPlay started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); const makeBadHost = prepareBadHost(zone); @@ -112,7 +112,7 @@ const testBadHostFirstPlay = async (t, zone) => { const testBadHostReplay1 = async (t, zone) => { t.log('badHost replay1 started'); const vowTools = prepareVowTools(zone); - const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, { + const { asyncFlow, adminAsyncFlow } = prepareTestAsyncFlowTools(t, zone, { vowTools, }); prepareBadHost(zone);