Skip to content

Commit

Permalink
feat(xsnap): record upstream commands as well as replies
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Aug 14, 2021
1 parent 8c4a16b commit fc9332f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/xsnap/src/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function recordXSnap(options, folderPath, { writeFileSync }) {

/** @param { Uint8Array} msg */
async function handleCommand(msg) {
nextFile('command').put(msg);
const result = await handle(msg);
nextFile('reply').put(result);
return result;
Expand Down Expand Up @@ -213,7 +214,7 @@ export async function replayXSnap(
const [_match, digits, kind] = parts;
const seq = parseInt(digits, 10);
console.log(folder, seq, kind);
if (running && kind !== 'reply') {
if (running && !['command', 'reply'].includes(kind)) {
// eslint-disable-next-line no-await-in-loop
await running;
running = undefined;
Expand All @@ -230,6 +231,9 @@ export async function replayXSnap(
case 'issueCommand':
running = it.issueCommand(file.getData());
break;
case 'command':
// ignore; we already know how to reply
break;
case 'reply':
replies.put(file.getData());
break;
Expand Down
6 changes: 4 additions & 2 deletions packages/xsnap/test/test-replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const transcript1 = [
'/xsnap-tests/00001-evaluate.dat',
'issueCommand(ArrayBuffer.fromString("Hello, World!"));',
],
['/xsnap-tests/00002-reply.dat', ''],
['/xsnap-tests/00002-command.dat', '{"compute":54'],
['/xsnap-tests/00003-reply.dat', ''],
];

test('record: evaluate and issueCommand', async t => {
Expand Down Expand Up @@ -72,6 +73,7 @@ test('replay', async t => {

t.deepEqual(done, [
['/xs-test/', 1, 'evaluate'],
['/xs-test/', 2, 'reply'],
['/xs-test/', 2, 'command'],
['/xs-test/', 3, 'reply'],
]);
});

0 comments on commit fc9332f

Please sign in to comment.