From 5dc616308fc00fcd966f3342e855747f9ca07d11 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 25 Jan 2022 11:22:21 -0800 Subject: [PATCH] test(swingset): check vatstore/vatExit are present in all worker types closes #2643 --- packages/SwingSet/test/workers/bootstrap.js | 11 +++++-- packages/SwingSet/test/workers/test-worker.js | 32 ++++++++++++++++--- packages/SwingSet/test/workers/vat-target.js | 24 ++++++++++++-- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/packages/SwingSet/test/workers/bootstrap.js b/packages/SwingSet/test/workers/bootstrap.js index f7042c291cc..3b9ecd0eeec 100644 --- a/packages/SwingSet/test/workers/bootstrap.js +++ b/packages/SwingSet/test/workers/bootstrap.js @@ -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', ]); } @@ -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; }, }); } diff --git a/packages/SwingSet/test/workers/test-worker.js b/packages/SwingSet/test/workers/test-worker.js index 94a4e13ccc5..7662c73506a 100644 --- a/packages/SwingSet/test/workers/test-worker.js +++ b/packages/SwingSet/test/workers/test-worker.js @@ -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, diff --git a/packages/SwingSet/test/workers/vat-target.js b/packages/SwingSet/test/workers/vat-target.js index cce087e1baa..ecce1de19a9 100644 --- a/packages/SwingSet/test/workers/vat-target.js +++ b/packages/SwingSet/test/workers/vat-target.js @@ -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; @@ -36,7 +36,11 @@ 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 @@ -44,7 +48,21 @@ export function buildRootObject(vatPowers, vatParameters) { 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: