Skip to content

Commit

Permalink
test(async-flow): update replay-membrane-eventual
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 4, 2024
1 parent 55a81f6 commit b9398d0
Showing 1 changed file with 55 additions and 28 deletions.
83 changes: 55 additions & 28 deletions packages/async-flow/test/replay-membrane-eventual.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { prepareBijection } from '../src/bijection.js';
import { makeReplayMembrane } from '../src/replay-membrane.js';

/**
* @import {PromiseKit} from '@endo/promise-kit'
* @import {Zone} from '@agoric/base-zone'
* @import {LogStore} from '../src/log-store.js';
* @import {Bijection} from '../src/bijection.js';
Expand All @@ -41,11 +40,19 @@ const preparePingee = zone =>
* @typedef {ReturnType<ReturnType<preparePingee>>} Pingee
*/

const testMode = /** @type {const} */ ({
normal: 'normal',
noEventualSend: 'noEventualSend',
retry: 'retry',
});

/**
* @param {any} t
* @param {Zone} zone
* @param {testMode[keyof testMode]} [mode]
*/
const testFirstPlay = async (t, zone) => {
const testFirstPlay = async (t, zone, mode = testMode.normal) => {
t.log('testFirstPlay', mode);
const vowTools = prepareVowTools(zone);
const { makeVowKit } = vowTools;
const makeLogStore = prepareLogStore(zone);
Expand All @@ -63,6 +70,7 @@ const testFirstPlay = async (t, zone) => {
vowTools,
watchWake,
panic,
enableEventualSend: mode !== testMode.noEventualSend,
});

const p1 = mem.hostToGuest(v1);
Expand Down Expand Up @@ -109,8 +117,10 @@ const testFirstPlay = async (t, zone) => {
/**
* @param {any} t
* @param {Zone} zone
* @param {testMode[keyof testMode]} [mode]
*/
const testReplay = async (t, zone) => {
const testReplay = async (t, zone, mode = testMode.normal) => {
t.log('testReplay', mode);
const vowTools = prepareVowTools(zone);
prepareLogStore(zone);
prepareBijection(zone);
Expand All @@ -129,22 +139,26 @@ const testReplay = async (t, zone) => {

const dump = log.dump();
const v3 = dump[3][2];
t.deepEqual(dump, [
const beforeY = [
['checkCall', pingee, 'ping', ['call'], 0],
['doReturn', 0, undefined],
['checkSend', pingee, 'ping', ['send'], 2],
['doReturn', 2, v3],
['checkSendOnly', pingee, 'ping', ['sendOnly'], 4],
['doFulfill', v3, undefined],
['doFulfill', v1, 'x'],
]);
];
const afterY = [['doFulfill', v2, 'y']];
const initialDump = beforeY;
t.deepEqual(dump, initialDump);

const mem = makeReplayMembrane({
log,
bijection,
vowTools,
watchWake,
panic,
enableEventualSend: mode !== testMode.noEventualSend,
});
t.true(log.isReplaying());
t.is(log.getIndex(), 0);
Expand All @@ -159,38 +173,32 @@ const testReplay = async (t, zone) => {
mem.wake();
t.true(log.isReplaying());
t.is(log.getIndex(), 0);
t.deepEqual(log.dump(), [
['checkCall', pingee, 'ping', ['call'], 0],
['doReturn', 0, undefined],
['checkSend', pingee, 'ping', ['send'], 2],
['doReturn', 2, v3],
['checkSendOnly', pingee, 'ping', ['sendOnly'], 4],
['doFulfill', v3, undefined],
['doFulfill', v1, 'x'],
]);
t.deepEqual(log.dump(), initialDump);

const pingSend = E(guestPingee).ping('send');

E(guestPingee).ping('send');
// TODO Once https://github.com/endojs/endo/issues/2336 is fixed,
// the following `void` should not be needed. But strangely, TS isn't
// telling me a `void` is needed above, which is also incorrect.
void E.sendOnly(guestPingee).ping('sendOnly');

guestPingee.ping('call');

t.is(await p1, 'x');
t.is(await p2, 'y');
t.false(log.isReplaying());
let finalDump;
if (mode === testMode.noEventualSend) {
t.true(log.isReplaying());
finalDump = beforeY;
} else {
t.is(await p1, 'x');
t.is(await p2, 'y');
t.false(log.isReplaying());
finalDump = [...beforeY, ...afterY];
}

t.deepEqual(log.dump(), [
['checkCall', pingee, 'ping', ['call'], 0],
['doReturn', 0, undefined],
['checkSend', pingee, 'ping', ['send'], 2],
['doReturn', 2, v3],
['checkSendOnly', pingee, 'ping', ['sendOnly'], 4],
['doFulfill', v3, undefined],
['doFulfill', v1, 'x'],
['doFulfill', v2, 'y'],
]);
await eventLoopIteration();

t.deepEqual(log.dump(), finalDump);
return pingSend;
};

test.serial('test heap replay-membrane settlement', async t => {
Expand All @@ -215,3 +223,22 @@ test.serial('test durable replay-membrane settlement', async t => {
const zone3 = makeDurableZone(getBaggage(), 'durableRoot');
return testReplay(t, zone3);
});

test.serial('test durable disabled eventual send', async t => {
annihilate();

nextLife();
const zone1 = makeDurableZone(getBaggage(), 'durableRoot');
await testFirstPlay(t, zone1);

nextLife();
const zone2 = makeDurableZone(getBaggage(), 'durableRoot');
await t.throwsAsync(() => testReplay(t, zone2, testMode.noEventualSend), {
message: /^panic over "\[Error: guest eventual applyMethod not enabled:/,
});

await eventLoopIteration();
nextLife();
const zone3 = makeDurableZone(getBaggage(), 'durableRoot');
await testReplay(t, zone3, testMode.retry);
});

0 comments on commit b9398d0

Please sign in to comment.