Skip to content

Commit

Permalink
fix: exercise callNow in local-worker case
Browse files Browse the repository at this point in the history
This is the only type of worker which can currently handle syscall.callNow.

The `node-subprocess` case theoretically could (the child subprocess could do a
blocking read of the kernel-to-worker pipe while waiting for the result), but
the code on either side of that pipe does not yet support that mode.

The `nodeWorker` (Node.js threads) case cannot, because threads cannot block,
at least not without heroics involving `Atomic` locks around a
results-bearing `SharedArrayBuffer`.

The old `xs-worker` case could not, for the same shallow implementation
reasons as `node-subprocess`, but the new `xsnap` -based XS worker should be
capable.

closes #1617
  • Loading branch information
warner authored and dckc committed Jan 21, 2021
1 parent 73487b1 commit c3c489e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
18 changes: 14 additions & 4 deletions packages/SwingSet/test/workers/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,32 @@ export function buildRootObject() {
return 'F good';
}

function checkA([pB, pC, pF]) {
function checkThree(three) {
return three === 3 ? 'three good' : `not three, got ${three}`;
}

function checkA([pB, pC, pF, three]) {
return Promise.all([
pB.then(checkResB),
pC.then(checkResC, checkErrC),
pF.then(checkResF),
Promise.resolve(three).then(checkThree),
]);
}

return harden({
bootstrap(vats) {
const pA = E(vats.target).zero(callbackObj, precD.promise, precE.promise);
bootstrap(vats, devices) {
const pA = E(vats.target).zero(
callbackObj,
precD.promise,
precE.promise,
devices.add,
);
const rp3 = E(vats.target).one();
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'], 'rp3 good']
return done; // expect: [['B good', 'C good', 'F good', 'three good'], 'rp3 good']
},
});
}
7 changes: 7 additions & 0 deletions packages/SwingSet/test/workers/device-add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function buildRootDeviceNode() {
return harden({
add(x, y) {
return x + y;
},
});
}
10 changes: 9 additions & 1 deletion packages/SwingSet/test/workers/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import '@agoric/install-ses';
import test from 'ava';
import { loadBasedir, buildVatController } from '../../src/index';

const expected = [['B good', 'C good', 'F good'], 'rp3 good'];
const expected = [['B good', 'C good', 'F good', 'three good'], 'rp3 good'];

async function makeController(managerType) {
const config = await loadBasedir(__dirname);
config.vats.target.creationOptions = { managerType };
const canCallNow = ['local'].indexOf(managerType) !== -1;
// const canCallNow = ['local', 'xs-worker'].indexOf(managerType) !== -1;
config.vats.target.parameters = { canCallNow };
config.devices = {
add: {
sourceSpec: require.resolve('./device-add.js'),
},
};
const c = await buildVatController(config, []);
return c;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/SwingSet/test/workers/vat-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@ function ignore(p) {
// inbound events ('dispatch'), which will provoke a set of outbound events
// ('syscall'), that cover the full range of the dispatch/syscall interface

export function buildRootObject(vatPowers) {
export function buildRootObject(vatPowers, vatParameters) {
console.log(`vat does buildRootObject`); // make sure console works
// note: XS doesn't appear to print console.log unless an exception happens
vatPowers.testLog('testLog works');

const { canCallNow } = vatParameters;
const precB = makePromiseKit();
const precC = makePromiseKit();
let callbackObj;

// crank 1:
// dispatch.deliver(target, method="zero", result=pA, args=[callbackObj, pD, pE])
// dispatch.deliver(target, method="zero", result=pA, args=[callbackObj, pD, pE, adder])
// syscall.subscribe(pD)
// syscall.subscribe(pE)
// syscall.send(callbackObj, method="callback", result=rp2, args=[11, 12]);
// syscall.subscribe(rp2)
// syscall.fulfillToData(pA, [pB, pC]);
function zero(obj, pD, pE) {
// syscall.callNow(adder, args=[1, 2]) -> 3
// syscall.fulfillToData(pA, [pB, pC, 3]);
function zero(obj, pD, pE, adder) {
callbackObj = obj;
const pF = E(callbackObj).callback(11, 12); // syscall.send
ignore(pD);
ignore(pE);
return [precB.promise, precC.promise, pF]; // syscall.fulfillToData
const three = canCallNow ? vatPowers.D(adder).add(1, 2) : 3;
return [precB.promise, precC.promise, pF, three]; // syscall.fulfillToData
}

// crank 2:
Expand Down

0 comments on commit c3c489e

Please sign in to comment.