Skip to content

Commit

Permalink
test(swingset-liveslots): Expand the signature of setupTestLiveslots
Browse files Browse the repository at this point in the history
Ref #6523
  • Loading branch information
gibson042 committed Mar 16, 2023
1 parent 835b5e5 commit 261e070
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 58 deletions.
38 changes: 28 additions & 10 deletions packages/swingset-liveslots/test/liveslots-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import {
import { kser } from './kmarshal.js';

/**
* @param {boolean} [skipLogging = false]
* @param {object} [options]
* @param {boolean} [options.skipLogging = false]
* @param {Map<string, string>} [options.kvStore = new Map()]
*/
export function buildSyscall(skipLogging) {
export function buildSyscall(options = {}) {
const { skipLogging = false, kvStore: fakestore = new Map() } = options;
const log = [];
const fakestore = new Map();
let sortedKeys;
let priorKeyReturned;
let priorKeyIndex;
Expand Down Expand Up @@ -152,23 +154,38 @@ export async function makeDispatch(
return { dispatch, testHooks };
}

function makeRPMaker() {
let idx = 0;
function makeRPMaker(nextNumber = 1) {
let idx = nextNumber - 1;
return () => {
idx += 1;
return `p-${idx}`;
};
}

/**
* @param {import('ava').ExecutionContext} t
* @param {Function} buildRootObject
* @param {string} vatName
* @param {object} [options]
* @param {boolean} [options.forceGC]
* @param {Map<string, string>} [options.kvStore = new Map()]
* @param {number} [options.nextPromiseImportNumber]
* @param {boolean} [options.skipLogging = false]
*/
export async function setupTestLiveslots(
t,
buildRootObject,
vatName,
forceGC,
skipLogging,
options = {},
) {
const { log, syscall, fakestore } = buildSyscall(skipLogging);
const nextRP = makeRPMaker();
const {
forceGC,
kvStore = new Map(),
nextPromiseImportNumber,
skipLogging = false,
} = options;
const { log, syscall, fakestore } = buildSyscall({ skipLogging, kvStore });
const nextRP = makeRPMaker(nextPromiseImportNumber);
const { dispatch, testHooks } = await makeDispatch(
syscall,
buildRootObject,
Expand Down Expand Up @@ -215,7 +232,7 @@ export async function setupTestLiveslots(
for (const [vpid, rejected, value] of l.resolutions) {
if (vpid === rp) {
if (rejected) {
throw Error(`vpid ${vpid} rejected with ${value}`);
throw Error(`vpid ${rp} rejected with ${value}`);
} else {
return value; // resolved successfully
}
Expand Down Expand Up @@ -249,6 +266,7 @@ export async function setupTestLiveslots(

return {
v,
dispatch,
dispatchMessage,
dispatchMessageSuccessfully,
dispatchDropExports,
Expand Down
16 changes: 8 additions & 8 deletions packages/swingset-liveslots/test/storeGC/test-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test.serial('store lifecycle 1', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);

// lerv -> Lerv Create store
Expand Down Expand Up @@ -100,7 +100,7 @@ test.serial('store lifecycle 2', async t => {
dispatchMessageSuccessfully,
dispatchDropExports,
dispatchRetireExports,
} = await setupTestLiveslots(t, buildRootObject, 'bob', true);
} = await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -176,7 +176,7 @@ test.serial('store lifecycle 3', async t => {
dispatchMessageSuccessfully,
dispatchDropExports,
dispatchRetireExports,
} = await setupTestLiveslots(t, buildRootObject, 'bob', true);
} = await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -213,7 +213,7 @@ test.serial('store lifecycle 3', async t => {
// test 4: lerv -> Lerv -> LERv -> LeRv -> lerv
test.serial('store lifecycle 4', async t => {
const { v, dispatchMessageSuccessfully, dispatchDropExports } =
await setupTestLiveslots(t, buildRootObject, 'bob', true);
await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -245,7 +245,7 @@ test.serial('store lifecycle 5', async t => {
dispatchMessageSuccessfully,
dispatchDropExports,
dispatchRetireExports,
} = await setupTestLiveslots(t, buildRootObject, 'bob', true);
} = await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -279,7 +279,7 @@ test.serial('store lifecycle 5', async t => {
// test 6: lerv -> Lerv -> LERv -> LeRv -> LeRV -> LeRv -> LeRV -> leRV -> lerv
test.serial('store lifecycle 6', async t => {
const { v, dispatchMessageSuccessfully, dispatchDropExports } =
await setupTestLiveslots(t, buildRootObject, 'bob', true);
await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -324,7 +324,7 @@ test.serial('store lifecycle 6', async t => {
// test 7: lerv -> Lerv -> LERv -> lERv -> LERv -> lERv -> lerv
test.serial('store lifecycle 7', async t => {
const { v, dispatchMessageSuccessfully, dispatchDropExports } =
await setupTestLiveslots(t, buildRootObject, 'bob', true);
await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down Expand Up @@ -363,7 +363,7 @@ test.serial('store lifecycle 7', async t => {
// test 8: lerv -> Lerv -> LERv -> LERV -> LERv -> LERV -> lERV -> lERv -> lerv
test.serial('store lifecycle 8', async t => {
const { v, dispatchMessageSuccessfully, dispatchDropExports } =
await setupTestLiveslots(t, buildRootObject, 'bob', true);
await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });

// lerv -> Lerv Create store
await dispatchMessageSuccessfully('makeAndHold');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test.serial('store refcount management 1', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -100,7 +100,7 @@ test.serial('store refcount management 2', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -136,7 +136,7 @@ test.serial('store refcount management 3', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -176,7 +176,7 @@ test.serial('presence refcount management 1', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -224,7 +224,7 @@ test.serial('presence refcount management 2', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -280,7 +280,7 @@ test.serial('remotable refcount management 1', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -316,7 +316,7 @@ test.serial('remotable refcount management 2', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.serial('assert known scalarMapStore ID', async t => {
// registered. Check it explicity here. If this test fails, consider
// updating `mapRef()` to use the new value.

const { testHooks } = await setupTestLiveslots(t, buildRootObject, 'bob', true);
const { testHooks } = await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });
const id = testHooks.obtainStoreKindID('scalarMapStore');
t.is(id, 2);
t.is(mapRef('INDEX'), 'o+v2/INDEX');
Expand Down
6 changes: 3 additions & 3 deletions packages/swingset-liveslots/test/storeGC/test-weak-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.serial('verify store weak key GC', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -108,7 +108,7 @@ test.serial('verify weakly held value GC', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down Expand Up @@ -147,7 +147,7 @@ test.serial('verify weakly held value GC', async t => {
// prettier-ignore
test.serial('verify presence weak key GC', async t => {
const { v, dispatchMessage, dispatchRetireImports, testHooks } =
await setupTestLiveslots(t, buildRootObject, 'bob', true);
await setupTestLiveslots(t, buildRootObject, 'bob', { forceGC: true });
const { fakestore } = v;

const presenceRef = 'o-5'; // Presence5
Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/test/test-baggage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test.serial('exercise baggage', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
const { fakestore } = v;

Expand Down
6 changes: 4 additions & 2 deletions packages/swingset-liveslots/test/test-initial-vrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function buildRootObject(vatPowers, vatParameters, baggage) {
}

test('initial vatstore contents', async t => {
const { v } = await setupTestLiveslots(t, buildRootObject, 'bob', true);
const { v } = await setupTestLiveslots(t, buildRootObject, 'bob', {
forceGC: true,
});
const { fakestore } = v;
const get = key => fakestore.get(key);

Expand Down Expand Up @@ -100,7 +102,7 @@ test('vrefs', async t => {
t,
buildRootObject,
'bob',
true,
{ forceGC: true },
);
// const { fakestore, dumpFakestore } = v;
const { fakestore } = v;
Expand Down
Loading

0 comments on commit 261e070

Please sign in to comment.