Skip to content

Commit

Permalink
test: fix up delays for array buffer test
Browse files Browse the repository at this point in the history
Refs: nodejs#735

Signed-off-by: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
mhdawson committed May 25, 2020
1 parent 45cb1d9 commit d8a00ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 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
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ 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 ], {
const child = require('./napi_child').spawnSync(process.argv[0],
['--expose-gc', '--no-concurrent-array-buffer-freeing', '--no-concurrent-array-buffer-sweeping', __filename ], {
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 d8a00ac

Please sign in to comment.