Skip to content
Permalink
Browse files

sandbox, feat: add gc test for sandbox.refesh.

  • Loading branch information...
xicilion committed Sep 17, 2018
1 parent 2aa1b8c commit ebeacf3cc5d8f3e3aa8dc950e896d5809c84440c
Showing with 28 additions and 10 deletions.
  1. +4 −10 test/fs_test.js
  2. +23 −0 test/vm_test.js
  3. +1 −0 test/vm_test/test_refresh1.js
@@ -682,18 +682,12 @@ describe('fs', () => {

it("readdir", () => {
var fl = fs.readdir(path.join(__dirname, 'vm_test'));
fl.sort((a, b) => {
if (a > b)
return 1;
if (a < b)
return -1;
return 0;
});
fl.sort();
var sz = fl.length;
assert.greaterThan(sz, 3);
assert.equal(fl[sz - 3], 't1.js');
assert.equal(fl[sz - 2], 't2.js');
assert.equal(fl[sz - 1], 'test_refresh.js');
assert.equal(fl[sz - 4], 't1.js');
assert.equal(fl[sz - 3], 't2.js');
assert.equal(fl[sz - 2], 'test_refresh.js');
});

it("writeFile & appendFile", () => {
@@ -513,6 +513,29 @@ describe("vm", () => {
});
});

it('gc of refresh', () => {
var sbox = new vm.SandBox({});

GC();
var no1 = test_util.countObject('Buffer');

var test = sbox.require('./vm_test/test_refresh1', __dirname);

GC();
assert.equal(test_util.countObject('Buffer'), no1 + 1);

test = undefined;
sbox.refresh();

GC();
assert.equal(test_util.countObject('Buffer'), no1);

test = sbox.require('./vm_test/test_refresh1', __dirname);

GC();
assert.equal(test_util.countObject('Buffer'), no1 + 1);
});

xit("block global hacker", () => {
sbox = new vm.SandBox({});
assert.throws(() => {
@@ -0,0 +1 @@
exports.buffer = new Buffer("abcd");

0 comments on commit ebeacf3

Please sign in to comment.
You can’t perform that action at this time.