Skip to content

Commit

Permalink
refactor(async-flow): simplify with zonified vow
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 8, 2024
1 parent 2cab795 commit 3f405ee
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 120 deletions.
6 changes: 2 additions & 4 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { annotateError, Fail, makeError, X } from '@endo/errors';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { PromiseWatcherI } from '@agoric/base-zone';
import { toPassableCap, VowShape } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { prepareVowTools, toPassableCap, VowShape } from '@agoric/vow';
import { makeReplayMembrane } from './replay-membrane.js';
import { prepareLogStore } from './log-store.js';
import { prepareWeakBijection } from './weak-bijection.js';
Expand Down Expand Up @@ -41,8 +40,7 @@ const AdminAsyncFlowI = M.interface('AsyncFlowAdmin', {
*/
export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
const {
// TODO https://github.com/Agoric/agoric-sdk/issues/9231
vowTools = prepareWatchableVowTools(outerZone),
vowTools = prepareVowTools(outerZone),
makeLogStore = prepareLogStore(outerZone),
makeWeakBijection = prepareWeakBijection(outerZone),
} = outerOptions;
Expand Down
37 changes: 14 additions & 23 deletions packages/async-flow/test/test-async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { makePromiseKit } from '@endo/promise-kit';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { isVow } from '@agoric/vow/src/vow-utils.js';
import { prepareVowTools } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
Expand Down Expand Up @@ -49,15 +48,13 @@ const prepareOrchestra = (zone, k = 1) =>

const firstLogLen = 7;

// TODO https://github.com/Agoric/agoric-sdk/issues/9231

/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testFirstPlay = async (t, zone, vowTools) => {
const testFirstPlay = async (t, zone) => {
t.log('firstPlay started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -130,10 +127,10 @@ const testFirstPlay = async (t, zone, vowTools) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testBadReplay = async (t, zone, vowTools) => {
const testBadReplay = async (t, zone) => {
t.log('badReplay started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -196,10 +193,10 @@ const testBadReplay = async (t, zone, vowTools) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testGoodReplay = async (t, zone, vowTools) => {
const testGoodReplay = async (t, zone) => {
t.log('goodReplay started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -299,10 +296,10 @@ const testGoodReplay = async (t, zone, vowTools) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testAfterPlay = async (t, zone, vowTools) => {
const testAfterPlay = async (t, zone) => {
t.log('testAfterPlay started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -334,41 +331,35 @@ const testAfterPlay = async (t, zone, vowTools) => {

await test.serial('test heap async-flow', async t => {
const zone = makeHeapZone('heapRoot');
const vowTools = prepareVowTools(zone);
return testFirstPlay(t, zone, vowTools);
return testFirstPlay(t, zone);
});

await test.serial('test virtual async-flow', async t => {
annihilate();
const zone = makeVirtualZone('virtualRoot');
const vowTools = prepareVowTools(zone);
return testFirstPlay(t, zone, vowTools);
return testFirstPlay(t, zone);
});

await test.serial('test durable async-flow', async t => {
annihilate();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools1 = prepareWatchableVowTools(zone1);
await testFirstPlay(t, zone1, vowTools1);
await testFirstPlay(t, zone1);

await eventLoopIteration();

nextLife();
const zone2 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools2 = prepareWatchableVowTools(zone2);
await testBadReplay(t, zone2, vowTools2);
await testBadReplay(t, zone2);

await eventLoopIteration();

nextLife();
const zone3 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools3 = prepareWatchableVowTools(zone3);
await testGoodReplay(t, zone3, vowTools3);
await testGoodReplay(t, zone3);

await eventLoopIteration();

nextLife();
const zone4 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools4 = prepareWatchableVowTools(zone4);
return testAfterPlay(t, zone4, vowTools4);
return testAfterPlay(t, zone4);
});
23 changes: 8 additions & 15 deletions packages/async-flow/test/test-bad-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { M } from '@endo/patterns';
import { makePromiseKit } from '@endo/promise-kit';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { prepareVowTools } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
Expand Down Expand Up @@ -40,15 +39,13 @@ const prepareBadHost = zone =>

/** @typedef {ReturnType<ReturnType<prepareBadHost>>} BadHost */

// TODO https://github.com/Agoric/agoric-sdk/issues/9231

/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testBadHostFirstPlay = async (t, zone, vowTools) => {
const testBadHostFirstPlay = async (t, zone) => {
t.log('badHost firstPlay started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -106,10 +103,10 @@ const testBadHostFirstPlay = async (t, zone, vowTools) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testBadHostReplay1 = async (t, zone, vowTools) => {
const testBadHostReplay1 = async (t, zone) => {
t.log('badHost replay1 started');
const vowTools = prepareVowTools(zone);
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand Down Expand Up @@ -183,27 +180,23 @@ const testBadHostReplay1 = async (t, zone, vowTools) => {

await test.serial('test heap async-flow bad host', async t => {
const zone = makeHeapZone('heapRoot');
const vowTools = prepareVowTools(zone);
return testBadHostFirstPlay(t, zone, vowTools);
return testBadHostFirstPlay(t, zone);
});

await test.serial('test virtual async-flow bad host', async t => {
annihilate();
const zone = makeVirtualZone('virtualRoot');
const vowTools = prepareVowTools(zone);
return testBadHostFirstPlay(t, zone, vowTools);
return testBadHostFirstPlay(t, zone);
});

await test.serial('test durable async-flow bad host', async t => {
annihilate();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools1 = prepareWatchableVowTools(zone1);
await testBadHostFirstPlay(t, zone1, vowTools1);
await testBadHostFirstPlay(t, zone1);

await eventLoopIteration();

nextLife();
const zone3 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools3 = prepareWatchableVowTools(zone3);
return testBadHostReplay1(t, zone3, vowTools3);
return testBadHostReplay1(t, zone3);
});
17 changes: 6 additions & 11 deletions packages/async-flow/test/test-convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { X, makeError, q } from '@endo/errors';
import { Far, getInterfaceOf, passStyleOf } from '@endo/pass-style';
import { prepareVowTools } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { isVow } from '@agoric/vow/src/vow-utils.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
Expand All @@ -22,10 +21,10 @@ import { prepareWeakBijection } from '../src/weak-bijection.js';
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testConvert = (t, zone, { makeVowKit }, showOnConsole = false) => {
const testConvert = (t, zone, showOnConsole = false) => {
const { makeVowKit } = prepareVowTools(zone);
const makeBijection = prepareWeakBijection(zone);
const bij = zone.makeOnce('bij', makeBijection);

Expand Down Expand Up @@ -89,30 +88,26 @@ const testConvert = (t, zone, { makeVowKit }, showOnConsole = false) => {

test('test heap convert', t => {
const zone = makeHeapZone('heapRoot');
const vowTools = prepareVowTools(zone);
testConvert(t, zone, vowTools, asyncFlowVerbose());
testConvert(t, zone, asyncFlowVerbose());
});

test.serial('test virtual convert', t => {
annihilate();
const zone = makeVirtualZone('virtualRoot');
const vowTools = prepareVowTools(zone);
testConvert(t, zone, vowTools);
testConvert(t, zone);
});

test.serial('test durable convert', t => {
annihilate();

nextLife();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools1 = prepareWatchableVowTools(zone1);
testConvert(t, zone1, vowTools1);
testConvert(t, zone1);

// These converters keep their state only in the bijection,
// which loses all its memory between incarnations.

nextLife();
const zone2 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools2 = prepareWatchableVowTools(zone2);
testConvert(t, zone2, vowTools2);
testConvert(t, zone2);
});
17 changes: 6 additions & 11 deletions packages/async-flow/test/test-equate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { X, makeError } from '@endo/errors';
import { Far } from '@endo/pass-style';
import { prepareVowTools } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { isVow } from '@agoric/vow/src/vow-utils.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
Expand All @@ -22,10 +21,10 @@ import { makeEquate } from '../src/equate.js';
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testEquate = (t, zone, { makeVowKit }, showOnConsole = false) => {
const testEquate = (t, zone, showOnConsole = false) => {
const { makeVowKit } = prepareVowTools(zone);
const makeBijection = prepareWeakBijection(zone);
const bij = zone.makeOnce('bij', makeBijection);

Expand Down Expand Up @@ -92,30 +91,26 @@ const testEquate = (t, zone, { makeVowKit }, showOnConsole = false) => {

test('test heap equate', t => {
const zone = makeHeapZone('heapRoot');
const vowTools = prepareVowTools(zone);
testEquate(t, zone, vowTools, asyncFlowVerbose());
testEquate(t, zone, asyncFlowVerbose());
});

test.serial('test virtual equate', t => {
annihilate();
const zone = makeVirtualZone('virtualRoot');
const vowTools = prepareVowTools(zone);
testEquate(t, zone, vowTools);
testEquate(t, zone);
});

test.serial('test durable equate', t => {
annihilate();

nextLife();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools1 = prepareWatchableVowTools(zone1);
testEquate(t, zone1, vowTools1);
testEquate(t, zone1);

// equate keeps its state only in the bijection,
// which loses all its memory between incarnations.

nextLife();
const zone2 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools2 = prepareWatchableVowTools(zone2);
testEquate(t, zone2, vowTools2);
testEquate(t, zone2);
});
21 changes: 8 additions & 13 deletions packages/async-flow/test/test-log-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {

import { Fail } from '@endo/errors';
import { prepareVowTools, toPassableCap } from '@agoric/vow';
import { prepareVowTools as prepareWatchableVowTools } from '@agoric/vat-data/vow.js';
import { makeHeapZone } from '@agoric/zone/heap.js';
import { makeVirtualZone } from '@agoric/zone/virtual.js';
import { makeDurableZone } from '@agoric/zone/durable.js';
Expand All @@ -18,9 +17,9 @@ import { prepareLogStore } from '../src/log-store.js';
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} vowTools
*/
const testLogStorePlay = async (t, zone, { makeVowKit }) => {
const testLogStorePlay = async (t, zone) => {
const { makeVowKit } = prepareVowTools(zone);
const makeLogStore = prepareLogStore(zone);

const log = zone.makeOnce('log', () => makeLogStore());
Expand Down Expand Up @@ -54,9 +53,9 @@ const testLogStorePlay = async (t, zone, { makeVowKit }) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {VowTools} _vowTools
*/
const testLogStoreReplay = async (t, zone, _vowTools) => {
const testLogStoreReplay = async (t, zone) => {
prepareVowTools(zone);
prepareLogStore(zone);

const log = /** @type {LogStore} */ (
Expand Down Expand Up @@ -85,27 +84,23 @@ const testLogStoreReplay = async (t, zone, _vowTools) => {

await test('test heap log-store', async t => {
const zone = makeHeapZone('heapRoot');
const vowTools = prepareVowTools(zone);
return testLogStorePlay(t, zone, vowTools);
return testLogStorePlay(t, zone);
});

await test.serial('test virtual log-store', async t => {
annihilate();
const zone = makeVirtualZone('virtualRoot');
const vowTools = prepareVowTools(zone);
return testLogStorePlay(t, zone, vowTools);
return testLogStorePlay(t, zone);
});

await test.serial('test durable log-store', async t => {
annihilate();

nextLife();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools1 = prepareWatchableVowTools(zone1);
await testLogStorePlay(t, zone1, vowTools1);
await testLogStorePlay(t, zone1);

nextLife();
const zone2 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools2 = prepareWatchableVowTools(zone2);
return testLogStoreReplay(t, zone2, vowTools2);
return testLogStoreReplay(t, zone2);
});
Loading

0 comments on commit 3f405ee

Please sign in to comment.