-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(swingset): add controller.terminateVat(vatID, reason) #9253
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions
27
packages/SwingSet/test/external-termination/bootstrap-external-termination.js
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,27 @@ | ||
import { Far, E } from '@endo/far'; | ||
|
||
export function buildRootObject() { | ||
let vatAdmin; | ||
let bcap; | ||
let root; | ||
let adminNode; | ||
let exitval; | ||
|
||
return Far('root', { | ||
bootstrap: async (vats, devices) => { | ||
vatAdmin = await E(vats.vatAdmin).createVatAdminService(devices.vatAdmin); | ||
bcap = await E(vatAdmin).getNamedBundleCap('doomed'); | ||
const res = await E(vatAdmin).createVat(bcap); | ||
root = res.root; | ||
adminNode = res.adminNode; | ||
E(adminNode) | ||
.done() | ||
.then( | ||
happy => (exitval = ['fulfill', happy]), | ||
sad => (exitval = ['reject', sad]), | ||
); | ||
}, | ||
ping: async count => E(root).ping(count), | ||
getExitVal: () => exitval, | ||
}); | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/SwingSet/test/external-termination/external-termination.test.js
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 { kser, kunser } from '@agoric/kmarshal'; | ||
import { initializeSwingset, makeSwingsetController } from '../../src/index.js'; | ||
|
||
const bfile = name => new URL(name, import.meta.url).pathname; | ||
|
||
const testExternalTermination = async (t, defaultManagerType) => { | ||
/** @type {SwingSetConfig} */ | ||
const config = { | ||
defaultManagerType, | ||
bootstrap: 'bootstrap', | ||
vats: { | ||
bootstrap: { sourceSpec: bfile('./bootstrap-external-termination.js') }, | ||
}, | ||
bundles: { | ||
doomed: { sourceSpec: bfile('./vat-doomed.js') }, | ||
}, | ||
}; | ||
|
||
const kernelStorage = initSwingStore().kernelStorage; | ||
await initializeSwingset(config, [], kernelStorage); | ||
const c = await makeSwingsetController(kernelStorage); | ||
t.teardown(c.shutdown); | ||
c.pinVatRoot('bootstrap'); | ||
await c.run(); | ||
|
||
const getVatIDs = () => c.dump().vatTables.map(vt => vt.vatID); | ||
|
||
// vat-doomed should now be running. We casually assume the new vat | ||
// has the last ID | ||
const vatIDs = getVatIDs(); | ||
const vatID = vatIDs[vatIDs.length - 1]; | ||
|
||
{ | ||
const kpid = c.queueToVatRoot('bootstrap', 'ping', [1]); | ||
await c.run(); | ||
t.is(kunser(c.kpResolution(kpid)), 1); | ||
} | ||
{ | ||
const kpid = c.queueToVatRoot('bootstrap', 'getExitVal'); | ||
await c.run(); | ||
t.is(kunser(c.kpResolution(kpid)), undefined); | ||
} | ||
|
||
// The "vat has been terminated" flags are set synchronously during | ||
// c.terminateVat(), as well as all the vat's promises being | ||
// rejected. The deletion of state happens during the first cleanup | ||
// crank, which (since we aren't limiting it with a runPolicy) | ||
// cleans to completion during this c.run() | ||
|
||
c.terminateVat(vatID, kser('doom!')); | ||
await c.run(); | ||
|
||
t.false(getVatIDs().includes(vatID)); | ||
|
||
{ | ||
// this provokes noise: liveslots logs one RemoteError | ||
const kpid = c.queueToVatRoot('bootstrap', 'ping', [1]); | ||
await c.run(); | ||
t.is(c.kpStatus(kpid), 'rejected'); | ||
t.deepEqual(kunser(c.kpResolution(kpid)), Error('vat terminated')); | ||
} | ||
|
||
{ | ||
const kpid = c.queueToVatRoot('bootstrap', 'getExitVal'); | ||
await c.run(); | ||
t.deepEqual(kunser(c.kpResolution(kpid)), ['reject', 'doom!']); | ||
} | ||
}; | ||
|
||
test('external termination: local worker', async t => { | ||
await testExternalTermination(t, 'local'); | ||
}); | ||
|
||
test('external termination: xsnap worker', async t => { | ||
await testExternalTermination(t, 'xsnap'); | ||
}); |
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,7 @@ | ||
import { Far } from '@endo/far'; | ||
|
||
export function buildRootObject() { | ||
return Far('doomed', { | ||
ping: count => count, | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how strict we should be about assert patterns, but this is the convention AIUI: