Skip to content

Commit

Permalink
Merge pull request #6924 from Agoric/call-startvat-properly
Browse files Browse the repository at this point in the history
test(liveslots): call startVat properly in liveslots-helpers.js
  • Loading branch information
mergify[bot] authored Feb 7, 2023
2 parents d3c6e8a + 6066068 commit 7cd4bcf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 40 deletions.
8 changes: 2 additions & 6 deletions packages/swingset-liveslots/src/liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -1634,9 +1634,6 @@ function build(
// we return 'possiblyDeadSet' for unit tests
return harden({
dispatch,
startVat,
vatGlobals,
inescapableGlobalProperties,
m,
possiblyDeadSet,
testHooks,
Expand All @@ -1655,7 +1652,7 @@ function build(
* @param {Pick<Console, 'debug' | 'log' | 'info' | 'warn' | 'error'>} [liveSlotsConsole]
* @param {*} [buildVatNamespace]
*
* @returns {*} { vatGlobals, inescapableGlobalProperties, dispatch }
* @returns {*} { dispatch }
*
* setBuildRootObject should be called, once, with a function that will
* create a root object for the new vat The caller provided buildRootObject
Expand Down Expand Up @@ -1697,10 +1694,9 @@ export function makeLiveSlots(
liveSlotsConsole,
buildVatNamespace,
);
const { dispatch, startVat, possiblyDeadSet, testHooks } = r; // omit 'm'
const { dispatch, possiblyDeadSet, testHooks } = r; // omit 'm'
return harden({
dispatch,
startVat,
possiblyDeadSet,
testHooks,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/swingset-liveslots/test/liveslots-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function makeDispatch(
gcAndFinalize: makeGcAndFinalize(engineGC),
meterControl: makeDummyMeterControl(),
});
const { dispatch, startVat, testHooks } = makeLiveSlots(
const { dispatch, testHooks } = makeLiveSlots(
syscall,
vatID,
{},
Expand All @@ -149,7 +149,7 @@ export async function makeDispatch(
return { buildRootObject: build };
},
);
await startVat(kser());
await dispatch(['startVat', kser()]);
if (returnTestHooks) {
returnTestHooks[0] = testHooks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ test.serial('store refcount management 1', async t => {
);
const { fakestore } = v;

// TODO: once makeDispatch() delivers startVat properly, switch to this
// const [ mainID, mainVref ] = deduceCollectionID(fakestore, 'scalarMapStore', 1)
// t.is(fakestore.get(`vc.${mainID}.|entryCount`), '1');
// t.is(fakestore.get(`vc.${mainID}.sfoo`), vstr(null));
// `mainHolder` is created during startup
const [ mainID ] = deduceCollectionID(fakestore, 'scalarMapStore', 1)
t.is(fakestore.get(`vc.${mainID}.|entryCount`), '1');
t.is(fakestore.get(`vc.${mainID}.sfoo`), vstr(null));

await dispatchMessageSuccessfully('makeAndHold'); // creates Map6, holds in RAM[heldStore]
// `heldStore` is the most recent one created
const [ heldID, heldVref ] = deduceCollectionID(fakestore, 'scalarMapStore', 1);
// and `mainHolder` was created before that
const [ mainID, _mainVref ] = deduceCollectionID(fakestore, 'scalarMapStore', 2)
t.is(fakestore.get(`vc.${mainID}.|entryCount`), '1');
t.is(fakestore.get(`vc.${mainID}.sfoo`), vstr(null));

t.is(fakestore.get(`vc.${heldID}.|entryCount`), '0'); // heldStore is empty
t.is(fakestore.get(`vom.rc.${heldVref}`), undefined); // no vdata references
Expand Down
17 changes: 4 additions & 13 deletions packages/swingset-liveslots/test/test-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { kslot, kser, kunser } from './kmarshal.js';
import { buildSyscall, makeDispatch } from './liveslots-helpers.js';
import {
makeMessage,
makeStartVat,
makeBringOutYourDead,
makeResolve,
makeReject,
Expand Down Expand Up @@ -62,7 +63,6 @@ test('calls', async t => {
// root!two(pr.promise)
// pr.resolve('result')
await dispatch(makeMessage(rootA, 'two', [kslot('p-1')]));
matchIDCounterSet(t, log);
t.deepEqual(log.shift(), { type: 'subscribe', target: 'p-1' });
t.deepEqual(log.shift(), 'two true');

Expand Down Expand Up @@ -491,7 +491,6 @@ test('liveslots vs symbols', async t => {
type: 'resolve',
resolutions: [[rp1, false, kser(['ok', 'asyncIterator', 'one'])]],
});
matchIDCounterSet(t, log);
t.deepEqual(log, []);

// E(root)[arbitrarySymbol]('two')
Expand Down Expand Up @@ -939,7 +938,6 @@ test('disable disavow', async t => {
// root~.one() // sendOnly
await dispatch(makeMessage(rootA, 'one', []));
t.deepEqual(log.shift(), false);
matchIDCounterSet(t, log);
t.deepEqual(log, []);
});

Expand Down Expand Up @@ -1021,7 +1019,6 @@ test('disavow', async t => {
expectError(t, msg.info, /this Presence has been disavowed/);
t.deepEqual(log.shift(), Error('this Presence has been disavowed'));
t.deepEqual(log.shift(), 'tried to send to disavowed');
matchIDCounterSet(t, log);
t.deepEqual(log, []);
});

Expand Down Expand Up @@ -1098,11 +1095,6 @@ test('GC syscall.dropImports', async t => {
t.falsy(wr.deref());

// first it will check that there are no VO's holding onto it
t.deepEqual(log.shift(), {
type: 'vatstoreSet',
key: 'idCounters',
value: '{"exportID":10,"collectionID":5,"promiseID":5}',
});
const l2 = log.shift();
t.deepEqual(l2, {
type: 'vatstoreGet',
Expand Down Expand Up @@ -1162,7 +1154,6 @@ test('GC dispatch.retireImports', async t => {
// dispatch.retireImport into the vat
await dispatch(makeRetireImports(arg));
// for now, we only care that it doesn't crash
matchIDCounterSet(t, log);
t.like(log.shift(), { type: 'vatstoreGetNextKey' });
t.deepEqual(log, []);

Expand Down Expand Up @@ -1328,8 +1319,8 @@ test('dropImports', async t => {
const ls = makeLiveSlots(syscall, 'vatA', {}, {}, gcTools, undefined, () => ({
buildRootObject: build,
}));
const { dispatch, startVat, possiblyDeadSet } = ls;
await startVat(kser());
const { dispatch, possiblyDeadSet } = ls;
await dispatch(makeStartVat(kser()));
const allFRs = gcTools.getAllFRs();
t.is(allFRs.length, 2);
const FR = allFRs[0];
Expand Down Expand Up @@ -1459,7 +1450,7 @@ test('buildVatNamespace not called until after startVat', async t => {
buildRootObject,
}));
t.falsy(buildCalled);
await ls.startVat(kser());
await ls.dispatch(makeStartVat(kser()));
t.truthy(buildCalled);
});

Expand Down
5 changes: 0 additions & 5 deletions packages/swingset-liveslots/test/test-vpid-liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,12 @@ async function doVatResolveCase23(t, which, mode, stalls) {

if (which === 2) {
await dispatch(makeMessage(rootA, 'result', [], p1));
matchIDCounterSet(t, log);
// the vat knows it is the decider, does not subscribe
await dispatch(makeMessage(rootA, 'promise', [kslot(p1)]));
} else if (which === 3) {
await dispatch(makeMessage(rootA, 'promise', [kslot(p1)]));
// the vat subscribes to p1, it cannot know the future
t.deepEqual(log.shift(), { type: 'subscribe', target: p1 });
matchIDCounterSet(t, log);
await dispatch(makeMessage(rootA, 'result', [], p1));
// vat cannot unsubscribe, but is now the decider
} else {
Expand Down Expand Up @@ -590,7 +588,6 @@ async function doVatResolveCase4(t, mode) {

await dispatch(makeMessage(rootA, 'get', [kslot(p1)]));
t.deepEqual(log.shift(), { type: 'subscribe', target: p1 });
matchIDCounterSet(t, log);
t.deepEqual(log, []);

await dispatch(makeMessage(rootA, 'first', [kslot(target1)]));
Expand Down Expand Up @@ -726,7 +723,6 @@ async function doVatResolveCase7(t, mode) {
await dispatch(makeMessage(rootA, 'acceptPromise', [kslot(p1)]));
// the vat subscribes to p1, it cannot know the future
t.deepEqual(log.shift(), { type: 'subscribe', target: p1 });
matchIDCounterSet(t, log);

const target1 = 'o-1';
const target2 = 'o-2';
Expand Down Expand Up @@ -882,7 +878,6 @@ test('inter-vat circular promise references', async t => {
// const paB = 'p-19';

await dispatchA(makeMessage(rootA, 'genPromise', [], paA));
matchIDCounterSet(t, log);
t.deepEqual(log, []);

// await dispatchB(makeMessage(rootB, 'genPromise', [], pbB));
Expand Down
4 changes: 4 additions & 0 deletions packages/swingset-liveslots/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export function makeMessage(target, method, args = [], result = null) {
return vatDeliverObject;
}

export function makeStartVat(vatParameters) {
return harden(['startVat', vatParameters]);
}

export function makeBringOutYourDead() {
return harden(['bringOutYourDead']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,15 +1173,16 @@ test.serial('remotable refcount management 1', async t => {
const { v, dispatchMessageSuccessfully } = await setupTestLiveslots(t, buildRootObject, 'bob', true);
const { fakestore } = v;

await dispatchMessageSuccessfully('makeAndHoldRemotable');
// the Remotable is currently held by RAM, and doesn't get a vref
// until it is stored somewhere or exported

// holder Kind is the next-to-last created kind, which gets idCounters.exportID-2
const holderKindID = JSON.parse(fakestore.get(`idCounters`)).exportID - 2;
t.is(JSON.parse(fakestore.get(`vom.vkind.${holderKindID}`)).tag, 'holder');

await dispatchMessageSuccessfully('makeAndHoldRemotable');
// the Remotable is currently held by RAM, and doesn't get a vref
// until it is stored somewhere or exported

await dispatchMessageSuccessfully('prepareStore3');

// Now there are three VirtualHolder objects, each holding our
// Remotable. The Remotable's vref was the last thing assigned.
const remotableID = JSON.parse(fakestore.get(`idCounters`)).exportID - 1;
Expand Down Expand Up @@ -1215,12 +1216,11 @@ test.serial('remotable refcount management 2', async t => {
const { v, dispatchMessageSuccessfully } = await setupTestLiveslots(t, buildRootObject, 'bob', true);
const { fakestore } = v;

await dispatchMessageSuccessfully('makeAndHoldRemotable');
const holderKindID = JSON.parse(fakestore.get(`idCounters`)).exportID - 2;
t.is(JSON.parse(fakestore.get(`vom.vkind.${holderKindID}`)).tag, 'holder');

await dispatchMessageSuccessfully('makeAndHoldRemotable');
await dispatchMessageSuccessfully('prepareStore3');

await dispatchMessageSuccessfully('finishDropHolders');
// all three holders are gone
const holderVrefs = [2,3,4].map(instanceID => `o+${holderKindID}/${instanceID}`);
Expand Down

0 comments on commit 7cd4bcf

Please sign in to comment.