From 3d5f64c7e75ebf78e2b6e6d086d20ae52f6923c3 Mon Sep 17 00:00:00 2001 From: Kenvin Davies Date: Mon, 25 May 2020 12:11:18 -0400 Subject: [PATCH] test: fix up delays for array buffer test Signed-off-by: Michael Dawson PR-URL: https://github.com/nodejs/node-addon-api/pull/737 Refs: https://github.com/nodejs/node-addon-api/issues/735 Reviewed-By: Anna Henningsen --- test/arraybuffer.js | 4 ++++ test/buffer.js | 4 ++++ test/index.js | 11 +++++++++-- test/testUtil.js | 14 +++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/test/arraybuffer.js b/test/arraybuffer.js index 3013698..4d0681a 100644 --- a/test/arraybuffer.js +++ b/test/arraybuffer.js @@ -39,6 +39,8 @@ function test(binding) { }, () => { global.gc(); + }, + () => { assert.strictEqual(1, binding.arraybuffer.getFinalizeCount()); }, @@ -51,6 +53,8 @@ function test(binding) { }, () => { global.gc(); + }, + () => { assert.strictEqual(1, binding.arraybuffer.getFinalizeCount()); }, diff --git a/test/buffer.js b/test/buffer.js index 0c6e648..9b94a90 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -48,6 +48,8 @@ function test(binding) { }, () => { global.gc(); + }, + () => { assert.strictEqual(1, binding.buffer.getFinalizeCount()); }, @@ -60,6 +62,8 @@ function test(binding) { }, () => { global.gc(); + }, + () => { assert.strictEqual(1, binding.buffer.getFinalizeCount()); }, ]); diff --git a/test/index.js b/test/index.js index 5fc752e..78c1c97 100644 --- a/test/index.js +++ b/test/index.js @@ -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); @@ -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', }); diff --git a/test/testUtil.js b/test/testUtil.js index 402c5c9..dfd7fab 100644 --- a/test/testUtil.js +++ b/test/testUtil.js @@ -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; @@ -18,7 +30,7 @@ function runGCTests(tests, i, title) { } setImmediate(() => { global.gc(); - runGCTests(tests, i + 1, title); + tick(10, runGCTests(tests, i + 1, title)); }); } }