Skip to content

Commit

Permalink
chore: use proper numerical sort in test-gc-kernel.js
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Mar 29, 2022
1 parent 3e5b090 commit 9e0a722
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/SwingSet/test/test-gc-kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import anylogger from 'anylogger';
import { test } from '../tools/prepare-test-env-ava.js';

// eslint-disable-next-line import/order
import { assert } from '@agoric/assert';
import { waitUntilQuiescent } from '../src/lib-nodejs/waitUntilQuiescent.js';
import { createSHA256 } from '../src/lib-nodejs/hasher.js';

import { parseVatSlot } from '../src/lib/parseVatSlots.js';
import buildKernel from '../src/kernel/index.js';
import { initializeKernel } from '../src/controller/initializeKernel.js';
import {
Expand Down Expand Up @@ -1019,6 +1021,25 @@ test('message to self', async t => {
p.gcActionsAre([]);
});

function sortVrefs(vrefs) {
// returns ['o+8', 'o+9', 'o+10', 'o+11']
function num(vref) {
const p = parseVatSlot(vref);
assert.equal(p.type, 'object');
assert.equal(p.allocatedByVat, true);
assert.equal(p.virtual, false);
return p.id;
}
vrefs.sort((a, b) => Number(num(a) - num(b)));
}

test('sortVrefs', t => {
const v1 = ['o+11', 'o+9', 'o+10', 'o+8'];
const exp = ['o+8', 'o+9', 'o+10', 'o+11'];
sortVrefs(v1);
t.deepEqual(v1, exp);
});

test('terminated vat', async t => {
// when a vat is terminated, anything it imported should be dropped, and
// its exports should not cause problems when they are released
Expand Down Expand Up @@ -1082,7 +1103,7 @@ test('terminated vat', async t => {

// find the highest export: doomedExport1 / doomedExport1Presence
let exports = Object.keys(vrefs).filter(vref => vref.startsWith('o+'));
exports.sort();
sortVrefs(exports);
const doomedExport1Vref = exports[exports.length - 1];
t.is(doomedExport1Vref, 'o+10'); // arbitrary
const doomedExport1Kref = vrefs[doomedExport1Vref];
Expand All @@ -1105,7 +1126,7 @@ test('terminated vat', async t => {
// now find the vref/kref for doomedExport2
vrefs = vrefsUsedByDoomed();
exports = Object.keys(vrefs).filter(vref => vref.startsWith('o+'));
exports.sort();
sortVrefs(exports);
const doomedExport2Vref = exports[exports.length - 1];
t.is(doomedExport2Vref, 'o+11'); // arbitrary
const doomedExport2Kref = vrefs[doomedExport2Vref];
Expand Down

0 comments on commit 9e0a722

Please sign in to comment.