Skip to content

Commit

Permalink
test(vow): test unhandled vow rejection machinery
Browse files Browse the repository at this point in the history
Run `yarn test:rejection` to test unhandled rejection reporting.

CAVEAT: AVA has no way to expect unhandled rejections and so will
fail the tests with this setting.
  • Loading branch information
michaelfig committed Dec 16, 2024
1 parent 255de62 commit 6cc3350
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/orchestration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"codegen": "scripts/fetch-chain-info.ts",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
"test": "ava",
"test": "SINK_UNHANDLED_VOW_REJECTIONS=1 ava",
"test:rejection": "ava",
"test:c8": "c8 --all $C8_OPTIONS ava",
"test:xs": "exit 0",
"lint": "run-s --continue-on-error lint:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/vow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "exit 0",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
"test": "ava",
"test": "SINK_UNHANDLED_VOW_REJECTIONS=1 ava",
"test:rejection": "ava",
"test:xs": "exit 0",
"lint-fix": "yarn lint:eslint --fix",
"lint": "run-s --continue-on-error lint:*",
Expand Down
4 changes: 3 additions & 1 deletion packages/vow/test/retryable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { prepareVowKit } from '../src/vow.js';
import { isVow } from '../src/vow-utils.js';
import { prepareRetryableTools } from '../src/retryable.js';
import { prepareVowRejectionTracker } from '../src/rejection-tracker.js';
import { makeWhen } from '../src/when.js';

/**
Expand All @@ -21,7 +22,8 @@ import { makeWhen } from '../src/when.js';
*/
const makeTestTools = ({ isRetryableReason = () => false } = {}) => {
const zone = makeHeapZone();
const makeVowKit = prepareVowKit(zone);
const makeVowRejectionTracker = prepareVowRejectionTracker(zone);
const makeVowKit = prepareVowKit(zone, makeVowRejectionTracker());
const when = makeWhen(isRetryableReason);

const { retryable, adminRetryableFlow } = prepareRetryableTools(zone, {
Expand Down
38 changes: 37 additions & 1 deletion packages/vow/test/watch-upgrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { prepareVowTools } from '../vat.js';
test.serial('vow resolve across upgrade', async t => {
annihilate();

t.plan(1);
t.plan(3);

await startLife(async baggage => {
const zone = makeDurableZone(baggage, 'durableRoot');
Expand All @@ -29,9 +29,29 @@ test.serial('vow resolve across upgrade', async t => {
},
});

const watcher2 = zone.exo('DurableVowTestWatcher2', undefined, {
onFulfilled(value) {
t.is(value, 42);
throw Error(`Error in handler ${value}`);
},
});

const testVowKit = zone.makeOnce('testVowKit', () => vowTools.makeVowKit());
const testVowKit2 = zone.makeOnce('testVowKit2', () =>
vowTools.makeVowKit(),
);
const testVowKit3 = zone.makeOnce('testVowKit3', () =>
vowTools.makeVowKit(),
);

vowTools.watch(testVowKit.vow, watcher);

vowTools.watch(testVowKit2.vow, watcher2);
const abandoned = new Promise(() => {});
testVowKit2.resolver.resolve(abandoned);

vowTools.watch(testVowKit3.vow, watcher2);
testVowKit3.resolver.resolve(42);
});

await startLife(
Expand All @@ -51,6 +71,22 @@ test.serial('vow resolve across upgrade', async t => {
},
});

zone.exo('DurableVowTestWatcher2', undefined, {
onFulfilled(value) {
t.fail(
`Second incarnation watcher2 onFulfilled triggered with value ${value}`,
);
},
onRejected(value) {
t.deepEqual(value, {
name: 'vatUpgraded',
upgradeMessage: 'vat upgraded',
incarnationNumber: 1,
});
return Promise.reject(Error('rejection from watcher2.onRejected'));
},
});

/** @type {import('../src/types.js').VowResolver} */
const testVowKitResolver = zone.makeOnce('testVowKit', () => {
t.fail('testVowKit maker called');
Expand Down

0 comments on commit 6cc3350

Please sign in to comment.