Skip to content

Commit

Permalink
fix(swingset): speed up vat-admin tests by pre-bundling the kernel
Browse files Browse the repository at this point in the history
As with other tests, we can shave 10-20s off these tests by only creating the
kernel bundles once, and sharing them across all test cases.
  • Loading branch information
warner committed Apr 23, 2021
1 parent 51cf813 commit 51d06e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
31 changes: 18 additions & 13 deletions packages/SwingSet/test/vat-admin/test-innerVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,47 @@ import '@agoric/install-metering-and-ses';
import path from 'path';
import test from 'ava';
import bundleSource from '@agoric/bundle-source';
import { buildVatController, loadBasedir } from '../../src';
import { buildKernelBundles, buildVatController, loadBasedir } from '../../src';

function nonBundleFunction(_E) {
return {};
}

async function doTestSetup(mode) {
const config = await loadBasedir(__dirname);
test.before(async t => {
const kernelBundles = await buildKernelBundles();
const newVatBundle = await bundleSource(path.join(__dirname, 'new-vat.js'));
const brokenVatBundle = await bundleSource(
path.join(__dirname, 'broken-vat.js'),
);
const nonBundle = `${nonBundleFunction}`;
const bundles = { newVatBundle, brokenVatBundle, nonBundle };
const c = await buildVatController(config, [mode, bundles]);
t.context.data = { kernelBundles, bundles };
});

async function doTestSetup(t, mode) {
const config = await loadBasedir(__dirname);
const { bundles, kernelBundles } = t.context.data;
const c = await buildVatController(config, [mode, bundles], {
kernelBundles,
});
return c;
}

test('VatAdmin inner vat creation', async t => {
const c = await doTestSetup('newVat');
for (let i = 0; i < 9; i += 1) {
// eslint-disable-next-line no-await-in-loop
await c.step();
}
const c = await doTestSetup(t, 'newVat');
await c.run();
t.deepEqual(c.dump().log, ['starting newVat test', '13']);
});

test('VatAdmin counter test', async t => {
const c = await doTestSetup('counters');
const c = await doTestSetup(t, 'counters');
await c.run();
await c.run();
t.deepEqual(c.dump().log, ['starting counter test', '4', '9', '2']);
});

test('VatAdmin broken vat creation', async t => {
const c = await doTestSetup('brokenVat');
const c = await doTestSetup(t, 'brokenVat');
await c.run();
t.deepEqual(c.dump().log, [
'starting brokenVat test',
Expand All @@ -47,7 +52,7 @@ test('VatAdmin broken vat creation', async t => {
});

test('error creating vat from non-bundle', async t => {
const c = await doTestSetup('non-bundle');
const c = await doTestSetup(t, 'non-bundle');
await c.run();
t.deepEqual(c.dump().log, [
'starting non-bundle test',
Expand All @@ -57,7 +62,7 @@ test('error creating vat from non-bundle', async t => {
});

test('VatAdmin get vat stats', async t => {
const c = await doTestSetup('vatStats');
const c = await doTestSetup(t, 'vatStats');
await c.run();
t.deepEqual(c.dump().log, [
'starting stats test',
Expand Down
13 changes: 10 additions & 3 deletions packages/SwingSet/test/vat-admin/test-replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getAllState,
setAllState,
} from '@agoric/swing-store-simple';
import { buildVatController } from '../../src';
import { buildKernelBundles, buildVatController } from '../../src';

function capdata(body, slots = []) {
return harden({ body, slots });
Expand All @@ -22,15 +22,20 @@ function copy(data) {
return JSON.parse(JSON.stringify(data));
}

test('replay bundleSource-based dynamic vat', async t => {
test.before(async t => {
const kernelBundles = await buildKernelBundles();
const dynamicBundle = await bundleSource(
path.join(__dirname, 'replay-dynamic.js'),
);
t.context.data = { kernelBundles, dynamicBundle };
});

test('replay bundleSource-based dynamic vat', async t => {
const config = {
vats: {
bootstrap: {
sourceSpec: path.join(__dirname, 'replay-bootstrap.js'),
parameters: { dynamicBundle },
parameters: { dynamicBundle: t.context.data.dynamicBundle },
},
},
bootstrap: 'bootstrap',
Expand All @@ -40,6 +45,7 @@ test('replay bundleSource-based dynamic vat', async t => {
{
const c1 = await buildVatController(copy(config), [], {
hostStorage: storage1,
kernelBundles: t.context.data.kernelBundles,
});
const r1 = c1.queueToVatExport(
'bootstrap',
Expand Down Expand Up @@ -90,6 +96,7 @@ test('replay bundleName-based dynamic vat', async t => {
{
const c1 = await buildVatController(copy(config), [], {
hostStorage: storage1,
kernelBundles: t.context.data.kernelBundles,
});
const r1 = c1.queueToVatExport(
'bootstrap',
Expand Down

0 comments on commit 51d06e8

Please sign in to comment.