Skip to content

Commit

Permalink
Merge pull request #1579 from Agoric/1568-test-with-ava
Browse files Browse the repository at this point in the history
chore: update more packages to use AVA for testing

* swingset
* bundle-source
* acorn-evnetual-send
* captp
* marshal
* import-bundle
  • Loading branch information
warner authored Aug 21, 2020
2 parents 5b156d4 + 7e184dd commit 23da2ca
Show file tree
Hide file tree
Showing 63 changed files with 1,106 additions and 1,423 deletions.
14 changes: 8 additions & 6 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"scripts": {
"build": "exit 0",
"test": "tap --no-coverage test/test-node-version.js && tap --no-coverage --jobs=1 --timeout 600 'test/**/test*.js'",
"test-nosort": "tape -r esm test/test-node-version.js && tape -r esm 'test/**/test*.js'",
"test": "ava",
"pretty-fix": "prettier --write '**/*.js'",
"pretty-check": "prettier --check '**/*.js'",
"lint-fix": "yarn lint --fix",
Expand All @@ -23,10 +22,7 @@
},
"devDependencies": {
"@agoric/install-metering-and-ses": "^0.1.1",
"esm": "^3.2.5",
"tap": "^14.10.5",
"tape": "^4.13.2",
"tape-promise": "^4.0.0"
"ava": "^3.11.1"
},
"dependencies": {
"@agoric/assert": "^0.0.8",
Expand All @@ -46,6 +42,7 @@
"@babel/core": "^7.5.0",
"@babel/generator": "^7.6.4",
"anylogger": "^0.21.0",
"esm": "^3.2.5",
"netstring-stream": "^1.0.1",
"re2": "^1.10.5",
"rollup": "^1.23.1",
Expand All @@ -72,5 +69,10 @@
},
"publishConfig": {
"access": "public"
},
"ava": {
"files": ["test/**/test-*.js"],
"require": ["esm"],
"timeout": "2m"
}
}
4 changes: 3 additions & 1 deletion packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ export async function buildVatController(
);

function makeNodeWorker() {
// TODO: after we move away from `-r esm` and use real ES6 modules, point
// this at nodeWorkerSupervisor.js instead of the CJS intermediate
const supercode = require.resolve(
'./kernel/vatManager/nodeWorkerSupervisor.js',
'./kernel/vatManager/nodeWorkerSupervisorCJS.js',
);
return new Worker(supercode);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/SwingSet/src/kernel/vatManager/nodeWorkerSupervisorCJS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// `tap` and `node -r esm` were able to allow the swingset process to create
// a thread (`new Worker()`) from the (ESM) supervisor file without problems,
// but for some reason AVA cannot. The file loaded into the new thread
// appears to lack the effects which `-r esm` had on the rest of the tree.
// This stub, written as CJS, exists to allow the real supervisor to be
// loaded under AVA. With luck, when we switch everything to use real ESM
// modules, and stop using `-r esm`, this should become unnecessary, and
// `controller.js` can point at `nodeWorkerSupervisor.js` instead.

// eslint-disable-next-line no-global-assign
require = require('esm')(module);
module.exports = require('./nodeWorkerSupervisor');
4 changes: 2 additions & 2 deletions packages/SwingSet/test/definition/test-vat-definition.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global harden */
import '@agoric/install-ses';
import tap from 'tap';
import test from 'ava';
import { buildVatController } from '../../src/index';

const mUndefined = { '@qclass': 'undefined' };
Expand All @@ -13,7 +13,7 @@ function capargs(args, slots = []) {
return capdata(JSON.stringify(args), slots);
}

tap.test('create with setup and buildRootObject', async t => {
test('create with setup and buildRootObject', async t => {
const config = {
vats: {
setup: {
Expand Down
15 changes: 0 additions & 15 deletions packages/SwingSet/test/message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ import { ignore } from './util';
// (which will only occur when using the comms layer, not in the
// direct-to-kernel test). 'outPipelined' holds these alternate expectations.

// 'patterns' is used to track which tests should be skipped (or which should
// be the only test run at all). Each defined pattern must call test(name) to
// add it to the list. In addition, if you want to skip something, call
// 'test. skipLocal(name)' (without the space) and/or 'test.
// skipComms(name)'. To mark a test as the only one to run, call `test.
// onlyLocal(name)' or 'test. onlyComms(name)' (again without the space). (We
// insert a space in this description so a simple 'grep' can still accurately
// show the presence of skipped/only tests).

// Initial Conditions: vat A (which hosts objects 'alice' and 'amy'), and vat
// B (hosting objects 'bob' and 'bert' and 'bill'). Initially alice has
// access to amy/bob/bert but not bill. Bob has access to bert and bill.
Expand Down Expand Up @@ -67,13 +58,7 @@ export function buildPatterns(log) {
const out = {};
const outPipelined = {};

// avoid dot-notation to preserve the utility of 'grep test(.)only'
const test = name => patterns.set(name, { local: 'test', comms: 'test' });
test['onlyLocal'] = n => patterns.set(n, { local: 'only', comms: 'test' });
test['onlyComms'] = n => patterns.set(n, { local: 'test', comms: 'only' });
test['skipLocal'] = n => patterns.set(n, { local: 'skip', comms: 'test' });
test['skipComms'] = n => patterns.set(n, { local: 'test', comms: 'skip' });
test['skipBoth'] = n => patterns.set(n, { local: 'skip', comms: 'skip' });

// bob!x()
test('a10');
Expand Down
6 changes: 2 additions & 4 deletions packages/SwingSet/test/metering/test-dynamic-vat-metered.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import '@agoric/install-metering-and-ses';
import bundleSource from '@agoric/bundle-source';
import tap from 'tap';
import test from 'ava';
import { buildVatController } from '../../src/index';
import makeNextLog from '../make-nextlog';

Expand All @@ -14,7 +14,7 @@ function capargs(args, slots = []) {
return capdata(JSON.stringify(args), slots);
}

tap.test('metering dynamic vats', async t => {
test('metering dynamic vats', async t => {
// we'll give this bundle to the loader vat, which will use it to create a
// new (metered) dynamic vat
const dynamicVatBundle = await bundleSource(
Expand Down Expand Up @@ -73,6 +73,4 @@ tap.test('metering dynamic vats', async t => {
['run exploded: RangeError: Allocate meter exceeded'],
'stay dead',
);

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import '@agoric/install-metering-and-ses';
import bundleSource from '@agoric/bundle-source';
import tap from 'tap';
import test from 'ava';
import { buildVatController } from '../../src/index';
import makeNextLog from '../make-nextlog';

Expand All @@ -17,7 +17,7 @@ function capargs(args, slots = []) {
// This test checks that dynamic vats (which are metered) can import bundles,
// and that those bundles are also metered.

tap.test('metering dynamic vat which imports bundle', async t => {
test('metering dynamic vat which imports bundle', async t => {
// We first create a static vat with vat-load-dynamic.js
const config = {
bootstrap: 'bootstrap',
Expand Down Expand Up @@ -96,6 +96,4 @@ tap.test('metering dynamic vat which imports bundle', async t => {
['run exploded: RangeError: Allocate meter exceeded'],
'whole dynamic vat is dead',
);

t.end();
});
6 changes: 2 additions & 4 deletions packages/SwingSet/test/metering/test-dynamic-vat-unmetered.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import '@agoric/install-metering-and-ses';
import bundleSource from '@agoric/bundle-source';
import tap from 'tap';
import test from 'ava';
import { buildVatController } from '../../src/index';
import makeNextLog from '../make-nextlog';

Expand All @@ -16,7 +16,7 @@ function capargs(args, slots = []) {

// Dynamic vats can be created without metering

tap.test('unmetered dynamic vat', async t => {
test('unmetered dynamic vat', async t => {
const config = {
bootstrap: 'bootstrap',
vats: {
Expand Down Expand Up @@ -66,6 +66,4 @@ tap.test('unmetered dynamic vat', async t => {
);
await c.run();
t.deepEqual(nextLog(), ['failed to explode'], 'metering disabled');

t.end();
});
22 changes: 11 additions & 11 deletions packages/SwingSet/test/metering/test-metering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { importBundle } from '@agoric/import-bundle';
import { makeMeter, makeMeteringTransformer } from '@agoric/transform-metering';
import * as babelCore from '@babel/core';
import re2 from 're2';
import tap from 'tap';
import test from 'ava';
import { waitUntilQuiescent } from '../../src/waitUntilQuiescent';

// Run a function under the control of a meter. The function must not have
Expand Down Expand Up @@ -90,7 +90,7 @@ async function meteredImportBundle(bundle, endowments) {
};
}

tap.test('metering a single bundle', async function testSingleBundle(t) {
test('metering a single bundle', async function testSingleBundle(t) {
const bundle = await bundleSource(require.resolve('./metered-code.js'));
harden(Object.getPrototypeOf(console));
const endowments = { console };
Expand All @@ -106,18 +106,18 @@ tap.test('metering a single bundle', async function testSingleBundle(t) {
let ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no'));
t.deepEqual(log2, ['started', 'done'], 'computation completed');
log2.splice(0);
t.equal(ok, true, 'meter should not be exhausted');
t.is(ok, true, 'meter should not be exhausted');

ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'compute'));
t.deepEqual(log2, ['started'], 'computation started but halted');
log2.splice(0);
t.equal(ok, false, 'meter should be exhausted (compute)');
t.is(ok, false, 'meter should be exhausted (compute)');

// Run the same code (without an infinite loop) against the old exhausted
// meter. It should halt right away.
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no'));
t.equal(log2.length, 0, 'computation did not start');
t.equal(ok, false, 'meter should be exhausted (still compute)');
t.is(log2.length, 0, 'computation did not start');
t.is(ok, false, 'meter should be exhausted (still compute)');

// Refill the meter, and the code should run again.
// refillFacet.combined(10000000);
Expand All @@ -126,13 +126,13 @@ tap.test('metering a single bundle', async function testSingleBundle(t) {
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no'));
t.deepEqual(log2, ['started', 'done'], 'computation completed');
log2.splice(0);
t.equal(ok, true, 'meter should not be exhausted');
t.is(ok, true, 'meter should not be exhausted');

// now check that metering catches infinite stack
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'stack'));
t.deepEqual(log2, ['started'], 'computation started but halted');
log2.splice(0);
t.equal(ok, false, 'meter should be exhausted (stack)');
t.is(ok, false, 'meter should be exhausted (stack)');

// Refill the meter, and the code should run again.
// refillFacet.combined(10000000);
Expand All @@ -141,18 +141,18 @@ tap.test('metering a single bundle', async function testSingleBundle(t) {
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no'));
t.deepEqual(log2, ['started', 'done'], 'computation completed');
log2.splice(0);
t.equal(ok, true, 'meter should not be exhausted');
t.is(ok, true, 'meter should not be exhausted');

// metering should catch primordial allocation too
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'allocate'));
t.deepEqual(log2, ['started'], 'computation started but halted');
log2.splice(0);
t.equal(ok, false, 'meter should be exhausted (allocate)');
t.is(ok, false, 'meter should be exhausted (allocate)');

// Refill the meter, and the code should run again.
refillFacet.allocate(10000000);
ok = await runBundleThunkUnderMeter(() => meterMe(log2, 'no'));
t.deepEqual(log2, ['started', 'done'], 'computation completed');
log2.splice(0);
t.equal(ok, true, 'meter should not be exhausted');
t.is(ok, true, 'meter should not be exhausted');
});
6 changes: 2 additions & 4 deletions packages/SwingSet/test/metering/test-within-vat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import '@agoric/install-metering-and-ses';
import bundleSource from '@agoric/bundle-source';
import tap from 'tap';
import test from 'ava';
import { buildVatController } from '../../src/index';
import makeNextLog from '../make-nextlog';

Expand All @@ -14,7 +14,7 @@ function capargs(args, slots = []) {
return capdata(JSON.stringify(args), slots);
}

tap.test('metering within a vat', async t => {
test('metering within a vat', async t => {
// we'll give this bundle to the vat, which will import it under metering
const bundle = await bundleSource(require.resolve('./metered-code.js'));
const config = {
Expand Down Expand Up @@ -143,6 +143,4 @@ tap.test('metering within a vat', async t => {
['run no', 'log2: started done', 'no exception'],
'compute meter refilled',
);

t.end();
});
Loading

0 comments on commit 23da2ca

Please sign in to comment.