-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjust swingStore import expectations
`importSwingStore()` has a consistency check which, for each vat, compares the `endPos` of the current snapshot against the `startPos` of the current transcript span. Now that the `save-snapshot` pseudo-entry is the last one of a transcript, these two values are expected to differ by one. Fixed the check, updated swingstore's test-exportImport.js to behave more like the real swingset, and added a new swingset test to exercise the whole run/export/import/run cycle, so we can discover this sort of thing locally in swingset's tests. Previously this only caused a failure of the "deployment-test", which doesn't run until all other CI has passed and the PR is at the front of the merge queue.
- Loading branch information
Showing
4 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
packages/SwingSet/test/transcript/test-state-sync-reload.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,117 @@ | ||
import test from 'ava'; | ||
import '@endo/init/debug.js'; | ||
import tmp from 'tmp'; | ||
import { | ||
initSwingStore, | ||
makeSwingStoreExporter, | ||
importSwingStore, | ||
} from '@agoric/swing-store'; | ||
import { initializeSwingset, makeSwingsetController } from '../../src/index.js'; | ||
import { buildKernelBundle } from '../../src/controller/initializeSwingset.js'; | ||
import { kunser } from '../../src/lib/kmarshal.js'; | ||
|
||
/** | ||
* @param {string} [prefix] | ||
* @returns {Promise<[string, () => void]>} | ||
*/ | ||
const tmpDir = prefix => | ||
new Promise((resolve, reject) => { | ||
tmp.dir({ unsafeCleanup: true, prefix }, (err, name, removeCallback) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve([name, removeCallback]); | ||
} | ||
}); | ||
}); | ||
|
||
const bfile = name => new URL(name, import.meta.url).pathname; | ||
|
||
test.before(async t => { | ||
const runtimeOptions = { kernelBundle: await buildKernelBundle() }; | ||
t.context.data = { runtimeOptions }; | ||
}); | ||
|
||
test('state-sync reload', async t => { | ||
const [dbDir, cleanup] = await tmpDir('testdb'); | ||
t.teardown(cleanup); | ||
|
||
const config = { | ||
snapshotInitial: 2, | ||
// the new pseudo-deliveries ('initialize-worker', | ||
// 'save-snapshot', and 'load-snapshot' all count against the | ||
// snapshotInterval. So setting it to 7 will get us 5 actual | ||
// deliveries between the two snapshot events. | ||
snapshotInterval: 7, | ||
defaultReapInterval: 'never', | ||
defaultManagerType: 'xsnap', | ||
bundles: { | ||
bundle: { sourceSpec: bfile('vat-bootstrap-transcript.js') }, | ||
}, | ||
vats: { | ||
bootstrap: { bundleName: 'bundle' }, | ||
}, | ||
bootstrap: 'bootstrap', | ||
}; | ||
|
||
const { kernelStorage, hostStorage } = initSwingStore(dbDir); | ||
const { commit } = hostStorage; | ||
const initOpts = { addComms: false, addVattp: false, addTimer: false }; | ||
await initializeSwingset(config, [], kernelStorage, initOpts); | ||
commit(); | ||
|
||
const { runtimeOptions } = t.context.data; | ||
const c1 = await makeSwingsetController(kernelStorage, {}, runtimeOptions); | ||
t.teardown(c1.shutdown); | ||
c1.pinVatRoot('bootstrap'); | ||
// const vatID = c1.vatNameToID('bootstrap'); | ||
|
||
const doCount = async c => { | ||
const kpid = c.queueToVatRoot('bootstrap', 'count', [], 'panic'); | ||
await c.run(); | ||
t.is(c.kpStatus(kpid), 'fulfilled'); | ||
return kunser(c.kpResolution(kpid)); | ||
}; | ||
|
||
// this should result in a final snapshot on d19, then a short | ||
// current transcript of just d20 = 'load-snapshot' and d21 = | ||
// 'message' (count -> 7) | ||
for (let i = 1; i <= 7; i += 1) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const res = await doCount(c1); | ||
t.is(res, i); | ||
} | ||
|
||
commit(); | ||
await c1.shutdown(); | ||
|
||
const exporter = makeSwingStoreExporter(dbDir); | ||
const exportData = new Map(); | ||
for await (const [k, v] of exporter.getExportData()) { | ||
if (v !== undefined) { | ||
exportData.set(k, v); | ||
} else { | ||
exportData.delete(k); | ||
} | ||
} | ||
const artifacts = new Map(); | ||
for await (const name of exporter.getArtifactNames()) { | ||
artifacts.set(name, exporter.getArtifact(name)); | ||
} | ||
|
||
const datasetExporter = { | ||
getExportData: () => [...exportData.entries()], | ||
getArtifactNames: () => [...artifacts.keys()], | ||
getArtifact: name => artifacts.get(name), | ||
close: () => 0, | ||
}; | ||
const ss2 = await importSwingStore(datasetExporter); | ||
const c2 = await makeSwingsetController( | ||
ss2.kernelStorage, | ||
{}, | ||
runtimeOptions, | ||
); | ||
t.teardown(c2.shutdown); | ||
|
||
t.is(await doCount(c2), 8); | ||
}); |
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