Skip to content

Commit

Permalink
test(xsnap): GC after snapshot vs restore
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jul 1, 2021
1 parent b20830f commit c4f0cec
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/xsnap/test/test-xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { xsnap } from '../src/xsnap.js';
import { ExitCode, ErrorCode } from '../api.js';

import { options, decode, encode, loader } from './message-tools.js';
import { unlinkSync } from 'fs';

const importMeta = { url: `file://${__filename}` };

Expand Down Expand Up @@ -335,3 +336,38 @@ test('normal close of pathological script', async t => {
await vat.terminate();
await hang;
});

test.failing('GC after snapshot vs restore', async t => {
const worker = xsnap({ ...options(io), meteringLimit: 0 });
t.teardown(worker.terminate);
const { meterUsage: { garbageCollectionCount: gcs1 } } = await worker.evaluate(`
print(Array.from(Array(2_000_000).keys()).length)
`);
t.log({ gcs1 });
t.true(gcs1 > 0);

const snapshot = './bloated.xss';
await worker.snapshot(snapshot);
t.teardown(() => unlinkSync(snapshot));
const clone = xsnap({ ...options(io), snapshot });
let workerGC = gcs1;
let cloneGC = 0;
let iters = 0;
const tmpAlloc = `
const tmp = { x: { y: { z: {} } } };
`;
for (; workerGC === gcs1; iters += 1) {
const {
meterUsage: { garbageCollectionCount: gcs3 },
// eslint-disable-next-line no-await-in-loop
} = await worker.evaluate(tmpAlloc);
workerGC = gcs3;
const {
meterUsage: { garbageCollectionCount: gcs4 },
// eslint-disable-next-line no-await-in-loop
} = await clone.evaluate(tmpAlloc);
cloneGC = gcs4;
}
t.log({ gcs1, workerGC, cloneGC, iters });
t.is(workerGC - gcs1, cloneGC);
});

0 comments on commit c4f0cec

Please sign in to comment.