Skip to content

Commit

Permalink
fixup! minor
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Mar 22, 2024
1 parent f8cb06f commit 3c5db54
Showing 1 changed file with 22 additions and 57 deletions.
79 changes: 22 additions & 57 deletions packages/zone/test/async-flow/test-async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getBaggage,
annihilate,
nextLife,
asyncFlowVerbose,
} from '../prepare-test-env-ava.js';

import { Fail } from '@endo/errors';
Expand Down Expand Up @@ -58,12 +57,9 @@ const firstLogLen = 7;
* @param {any} t
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testFirstPlay = async (t, zone, vowTools, showOnConsole = false) => {
if (showOnConsole) {
t.log('firstPlay started');
}
const testFirstPlay = async (t, zone, vowTools) => {
t.log('firstPlay started');
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand All @@ -80,9 +76,7 @@ const testFirstPlay = async (t, zone, vowTools, showOnConsole = false) => {
const { guestMethod } = {
async guestMethod(gOrch7, gP) {
t.is(this, 'context');
if (showOnConsole) {
t.log(' firstPlay about to await gP');
}
t.log(' firstPlay about to await gP');
await gP;
const g2 = gOrch7.vow();
const prod = gOrch7.scale(3);
Expand All @@ -97,9 +91,7 @@ const testFirstPlay = async (t, zone, vowTools, showOnConsole = false) => {
t.is(gErr.name, 'TypeError');

resolveStep(true);
if (showOnConsole) {
t.log(' firstPlay to hang awaiting g2');
}
t.log(' firstPlay to hang awaiting g2');
// awaiting a promise that won't be resolved until next incarnation
await g2;
t.fail('must not reach here in first incarnation');
Expand Down Expand Up @@ -135,22 +127,17 @@ const testFirstPlay = async (t, zone, vowTools, showOnConsole = false) => {
TypeError('Cannot mix BigInt and other types, use explicit conversions'),
],
]);
if (showOnConsole) {
t.log('firstPlay done');
}
t.log('firstPlay done');
return promiseStep;
};

/**
* @param {any} t
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testBadReplay = async (t, zone, vowTools, showOnConsole = false) => {
if (showOnConsole) {
t.log('badReplay started');
}
const testBadReplay = async (t, zone, vowTools) => {
t.log('badReplay started');
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand All @@ -165,9 +152,7 @@ const testBadReplay = async (t, zone, vowTools, showOnConsole = false) => {
const { guestMethod } = {
async guestMethod(gOrch7, gP) {
t.is(this, 'context');
if (showOnConsole) {
t.log(' badReplay about to await gP');
}
t.log(' badReplay about to await gP');
resolveStep(true);
await gP;
const g2 = gOrch7.vow();
Expand All @@ -177,9 +162,7 @@ const testBadReplay = async (t, zone, vowTools, showOnConsole = false) => {
t.is(prod, undefined);
t.is(gOrch7.scale(9n), undefined);

if (showOnConsole) {
t.log(' badReplay about to await g2');
}
t.log(' badReplay about to await g2');
// because of the replay failure, g2 should not settle in this incarnatuon
await g2;
t.fail('badReplay must not reach here');
Expand Down Expand Up @@ -217,23 +200,18 @@ const testBadReplay = async (t, zone, vowTools, showOnConsole = false) => {
makeCopyMap([[flow, replayProblem]]),
);

if (showOnConsole) {
t.log(' badReplay failure', flow.getOptFatalProblem().message);
t.log('badReplay done', await promiseStep);
}
t.log(' badReplay failures', flow.getOptFatalProblem());
t.log('badReplay done', await promiseStep);
return promiseStep;
};

/**
* @param {any} t
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testGoodReplay = async (t, zone, vowTools, showOnConsole = false) => {
if (showOnConsole) {
t.log('goodReplay started');
}
const testGoodReplay = async (t, zone, vowTools) => {
t.log('goodReplay started');
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand All @@ -248,9 +226,7 @@ const testGoodReplay = async (t, zone, vowTools, showOnConsole = false) => {
const { guestMethod } = {
async guestMethod(gOrch7, gP) {
t.is(this, 'context');
if (showOnConsole) {
t.log(' goodReplay about to await gP');
}
t.log(' goodReplay about to await gP');
await gP;
const g2 = gOrch7.vow();
const prod = gOrch7.scale(3);
Expand All @@ -265,14 +241,10 @@ const testGoodReplay = async (t, zone, vowTools, showOnConsole = false) => {
t.is(gErr.name, 'TypeError');

resolveStep(true);
if (showOnConsole) {
t.log(' goodReplay about to await g2');
}
t.log(' goodReplay about to await g2');
// awaiting a promise that won't be resolved until this incarnation
await g2;
if (showOnConsole) {
t.log(' goodReplay woke up!');
}
t.log(' goodReplay woke up!');
},
};

Expand Down Expand Up @@ -319,21 +291,16 @@ const testGoodReplay = async (t, zone, vowTools, showOnConsole = false) => {
t.is(await when(outcomeV), undefined);
t.deepEqual(flow.dump(), []);

if (showOnConsole) {
t.log('goodReplay done', await promiseStep);
}
t.log('goodReplay done', await promiseStep);
};

/**
* @param {any} t
* @param {import('@agoric/base-zone').Zone} zone
* @param {import('@agoric/vow').VowTools} vowTools
* @param {boolean} [showOnConsole]
*/
const testAfterPlay = async (t, zone, vowTools, showOnConsole = false) => {
if (showOnConsole) {
t.log('testAfterPlay started');
}
const testAfterPlay = async (t, zone, vowTools) => {
t.log('testAfterPlay started');
const { asyncFlow, adminAsyncFlow } = prepareAsyncFlowTools(zone, {
vowTools,
});
Expand All @@ -360,15 +327,13 @@ const testAfterPlay = async (t, zone, vowTools, showOnConsole = false) => {

t.deepEqual(flow.dump(), []);

if (showOnConsole) {
t.log('testAfterDoneReplay done');
}
t.log('testAfterDoneReplay done');
};

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

await test.serial('test virtual async-flow', async t => {
Expand Down Expand Up @@ -398,7 +363,7 @@ await test.serial('test durable async-flow', async t => {
nextLife();
const zone3 = makeDurableZone(getBaggage(), 'durableRoot');
const vowTools3 = prepareWatchableVowTools(zone3);
await testGoodReplay(t, zone3, vowTools3, asyncFlowVerbose());
await testGoodReplay(t, zone3, vowTools3);

await eventLoopIteration();

Expand Down

0 comments on commit 3c5db54

Please sign in to comment.