Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test(swingset): check vatstore/vatExit are present in all worker types #4378

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/SwingSet/test/workers/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ export function buildRootObject() {
return three === 3 ? 'three good' : `not three, got ${three}`;
}

function checkA([pB, pC, pF, three]) {
function checkA([pB, pC, pF, three, vs1, vs2, evt, evwft]) {
return Promise.all([
pB.then(checkResB),
pC.then(checkResC, checkErrC),
pF.then(checkResF),
Promise.resolve(three).then(checkThree),
checkThree(three),
vs1 === 'vsValue' ? 'vs1 good' : 'vs1 bad',
vs2 === undefined ? 'vs2 good' : 'vs2 bad',
evt === 'function' ? 'exit good' : 'exit bad',
evwft === 'function' ? 'exitWF good' : 'exitWF bad',
]);
}

Expand All @@ -69,7 +73,8 @@ export function buildRootObject() {
precD.resolve(callbackObj); // two
precE.reject(Error('four')); // three
const done = Promise.all([pA.then(checkA), rp3]);
return done; // expect: [['B good', 'C good', 'F good', 'three good'], 'rp3 good']
// expect: [['B good', 'C good', 'F good', 'three good', 'vs1 good', 'vs2 good', 'exit good', 'exitWF good'], 'rp3 good']
return done;
},
});
}
32 changes: 28 additions & 4 deletions packages/SwingSet/test/workers/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ import { test } from '../../tools/prepare-test-env-ava.js';

import { loadBasedir, buildVatController } from '../../src/index.js';

const expected = [['B good', 'C good', 'F good', 'three good'], 'rp3 good'];
function canBlock(managerType) {
// nodeworker cannot block: the thread-to-thread port it uses provides a
// strictly async API. The subprocess-node worker *should* be able to
// block, but we didn't bother implementing the return pathway, so treat it
// as non-blocking.
return managerType === 'local' || managerType === 'local';
}
const expected = [
[
'B good',
'C good',
'F good',
'three good',
'vs1 good',
'vs2 good',
'exit good',
'exitWF good',
],
'rp3 good',
];

async function makeController(managerType) {
const config = await loadBasedir(new URL('./', import.meta.url).pathname);
config.vats.target.creationOptions = { managerType, enableDisavow: true };
const canCallNow = ['local', 'xs-worker'].indexOf(managerType) !== -1;
config.vats.target.parameters = { canCallNow };
config.vats.target.creationOptions = {
managerType,
enableDisavow: true,
enableVatstore: canBlock(managerType),
};
const canCallNow = canBlock(managerType);
const canVatstore = canBlock(managerType);
config.vats.target.parameters = { canCallNow, canVatstore };
config.devices = {
add: {
sourceSpec: new URL('device-add.js', import.meta.url).pathname,
Expand Down
24 changes: 21 additions & 3 deletions packages/SwingSet/test/workers/vat-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function buildRootObject(vatPowers, vatParameters) {
// note: XS doesn't appear to print console.log unless an exception happens
vatPowers.testLog('testLog works');

const { canCallNow } = vatParameters;
const { canCallNow, canVatstore } = vatParameters;
const precB = makePromiseKit();
const precC = makePromiseKit();
let callbackObj;
Expand All @@ -36,15 +36,33 @@ export function buildRootObject(vatPowers, vatParameters) {
// syscall.dropImports([dropMe])
// syscall.send(callbackObj, method="callback", result=rp2, args=[11, 12]);
// syscall.subscribe(rp2)
// syscall.fulfillToData(pA, [pB, pC, 3]);
// syscall.vatstoreSet('key', 'vsValue')
// syscall.vatstoreGet('key') -> 'vsValue'
// syscall.vatstoreDelete('key')
// syscall.vatstoreGet('key') -> undefined
// syscall.fulfillToData(pA, [pB, pC, 3, 'vsValue', undefined, 'function', 'function']);
function zero(obj, pD, pE, adder, dropMe) {
callbackObj = obj;
const pF = E(callbackObj).callback(11, 12); // syscall.send
ignore(pD);
ignore(pE);
const three = canCallNow ? vatPowers.D(adder).add(1, 2) : 3;
vatPowers.disavow(dropMe);
return [precB.promise, precC.promise, pF, three]; // syscall.fulfillToData
let vs1;
let vs2;
if (canVatstore) {
vatPowers.vatstore.set('key', 'vsValue');
vs1 = vatPowers.vatstore.get('key');
vatPowers.vatstore.delete('key');
vs2 = vatPowers.vatstore.get('key');
} else {
vs1 = 'vsValue';
vs2 = undefined;
}
const evt = typeof vatPowers.exitVat;
const evwft = typeof vatPowers.exitVatWithFailure;
// syscall.fulfillToData:
return [precB.promise, precC.promise, pF, three, vs1, vs2, evt, evwft];
}

// crank 2:
Expand Down