-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a
reapAllVats
call to the controller
Closes #8626
- Loading branch information
Showing
6 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Far, E } from '@endo/far'; | ||
|
||
export function buildRootObject() { | ||
let vatAdmin; | ||
let bcap; | ||
|
||
return Far('root', { | ||
async bootstrap(vats, devices) { | ||
vatAdmin = await E(vats.vatAdmin).createVatAdminService(devices.vatAdmin); | ||
bcap = await E(vatAdmin).getNamedBundleCap('dumbo'); | ||
console.log('end of bootstrap, vatAdmin', vatAdmin); | ||
}, | ||
|
||
async createDynamicVats() { | ||
const roots = []; | ||
for (let i = 0; i < 3; i += 1) { | ||
const res = await E(vatAdmin).createVat(bcap); | ||
roots.push(res.root); | ||
} | ||
return roots; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// eslint-disable-next-line import/order | ||
import { test } from '../../tools/prepare-test-env-ava.js'; | ||
|
||
import { initSwingStore } from '@agoric/swing-store'; | ||
import { kunser } from '@agoric/kmarshal'; | ||
|
||
import { initializeSwingset, makeSwingsetController } from '../../src/index.js'; | ||
|
||
function bfile(name) { | ||
return new URL(name, import.meta.url).pathname; | ||
} | ||
|
||
test('reap all vats', async t => { | ||
/** @type {SwingSetConfig} */ | ||
const config = { | ||
defaultManagerType: 'local', | ||
defaultReapInterval: 4, | ||
bootstrap: 'bootstrap', | ||
vats: { | ||
bootstrap: { sourceSpec: bfile('bootstrap-reap-all.js') }, | ||
staticDumbo1: { bundleName: 'dumbo' }, | ||
staticDumbo2: { bundleName: 'dumbo' }, | ||
staticDumbo3: { bundleName: 'dumbo' }, | ||
}, | ||
bundles: { | ||
dumbo: { sourceSpec: bfile('vat-dumbo.js') }, | ||
}, | ||
}; | ||
|
||
const kernelStorage = initSwingStore().kernelStorage; | ||
await initializeSwingset(config, [], kernelStorage); | ||
const c = await makeSwingsetController(kernelStorage); | ||
t.teardown(c.shutdown); | ||
c.pinVatRoot('bootstrap'); | ||
c.pinVatRoot('staticDumbo1'); | ||
c.pinVatRoot('staticDumbo2'); | ||
c.pinVatRoot('staticDumbo3'); | ||
await c.run(); | ||
|
||
const kpid = c.queueToVatRoot('bootstrap', 'createDynamicVats'); | ||
await c.run(); | ||
|
||
const dynamicRoots = kunser(c.kpResolution(kpid)); | ||
for (let i = 0; i < 3; i += 1) { | ||
for (let j = 0; j < i + 1; j += 1) { | ||
c.queueToVatRoot(`staticDumbo${i + 1}`, 'doSomething', [ | ||
`staticDumbo${i + 1} #${j + 1}`, | ||
]); | ||
} | ||
} | ||
for (let i = 0; i < 3; i += 1) { | ||
for (let j = 0; j < i + 1; j += 1) { | ||
c.queueToVatObject(dynamicRoots[i], 'doSomething', [ | ||
`dynamicDumbo${i + 1} #${j + 1}`, | ||
]); | ||
} | ||
} | ||
// Note: no call to c.run() here, so all the above messages are still enqueued | ||
|
||
const dumpBefore = c.dump(); | ||
t.is(dumpBefore.acceptanceQueue.length, 12); | ||
t.is(dumpBefore.reapQueue.length, 0); | ||
|
||
c.reapAllVats(); | ||
const dumpPreReap = c.dump(); | ||
t.is(dumpPreReap.acceptanceQueue.length, 12); | ||
t.is(dumpPreReap.reapQueue.length, 11); | ||
t.deepEqual( | ||
dumpPreReap.reapQueue, | ||
// prettier-ignore | ||
['v1', 'v3', 'v6', 'v7', 'v8', 'v5', 'v2', 'v4', 'v9', 'v10', 'v11'], | ||
); | ||
|
||
await c.run(); | ||
const dumpPostReap = c.dump(); | ||
t.is(dumpPostReap.acceptanceQueue.length, 0); | ||
t.is(dumpPostReap.reapQueue.length, 0); | ||
|
||
t.pass(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Far } from '@endo/far'; | ||
|
||
export function buildRootObject() { | ||
return Far('root', { | ||
doSomething(msg) { | ||
console.log(`doSomething: ${msg}`); | ||
}, | ||
}); | ||
} |