Skip to content

Commit

Permalink
test: fix up delays for array buffer test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #737
Refs: #735
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
mhdawson committed May 25, 2020
1 parent 45cb1d9 commit beccf21
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test/arraybuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function test(binding) {
},
() => {
global.gc();
},
() => {
assert.strictEqual(1, binding.arraybuffer.getFinalizeCount());
},

Expand All @@ -51,6 +53,8 @@ function test(binding) {
},
() => {
global.gc();
},
() => {
assert.strictEqual(1, binding.arraybuffer.getFinalizeCount());
},

Expand Down
4 changes: 4 additions & 0 deletions test/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function test(binding) {
},
() => {
global.gc();
},
() => {
assert.strictEqual(1, binding.buffer.getFinalizeCount());
},

Expand All @@ -60,6 +62,8 @@ function test(binding) {
},
() => {
global.gc();
},
() => {
assert.strictEqual(1, binding.buffer.getFinalizeCount());
},
]);
Expand Down
11 changes: 9 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ let testModules = [
];

const napiVersion = Number(process.versions.napi)
const majorNodeVersion = process.versions.node.split('.')[0]

if (napiVersion < 3) {
testModules.splice(testModules.indexOf('callbackscope'), 1);
Expand Down Expand Up @@ -98,8 +99,14 @@ if (typeof global.gc === 'function') {

console.log('\nAll tests passed!');
} else {
// Make it easier to run with the correct (version-dependent) command-line args.
const child = require('./napi_child').spawnSync(process.argv[0], [ '--expose-gc', __filename ], {
// Construct the correct (version-dependent) command-line args.
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
if (majorNodeVersion >= 14) {
args.push('--no-concurrent-array-buffer-sweeping');
}
args.push(__filename);

const child = require('./napi_child').spawnSync(process.argv[0], args, {
stdio: 'inherit',
});

Expand Down
14 changes: 13 additions & 1 deletion test/testUtil.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Run each test function in sequence,
// with an async delay and GC call between each.

function tick(x, cb) {
function ontick() {
if (--x === 0) {
if (typeof cb === 'function') cb();
} else {
setImmediate(ontick);
}
}
setImmediate(ontick);
};

function runGCTests(tests, i, title) {
if (!i) {
i = 0;
Expand All @@ -18,7 +30,7 @@ function runGCTests(tests, i, title) {
}
setImmediate(() => {
global.gc();
runGCTests(tests, i + 1, title);
tick(10, runGCTests(tests, i + 1, title));
});
}
}
Expand Down

0 comments on commit beccf21

Please sign in to comment.