From 51d06e8827558ba9ae30c9d4e0e5bd7adf59a1b0 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 20 Apr 2021 23:50:15 -0700 Subject: [PATCH] fix(swingset): speed up vat-admin tests by pre-bundling the kernel 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. --- .../SwingSet/test/vat-admin/test-innerVat.js | 31 +++++++++++-------- .../SwingSet/test/vat-admin/test-replay.js | 13 ++++++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/SwingSet/test/vat-admin/test-innerVat.js b/packages/SwingSet/test/vat-admin/test-innerVat.js index 7f0a1baf839..ed766b9a603 100644 --- a/packages/SwingSet/test/vat-admin/test-innerVat.js +++ b/packages/SwingSet/test/vat-admin/test-innerVat.js @@ -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', @@ -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', @@ -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', diff --git a/packages/SwingSet/test/vat-admin/test-replay.js b/packages/SwingSet/test/vat-admin/test-replay.js index fdae1445007..39a9c0e1683 100644 --- a/packages/SwingSet/test/vat-admin/test-replay.js +++ b/packages/SwingSet/test/vat-admin/test-replay.js @@ -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 }); @@ -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', @@ -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', @@ -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',