From beccf2145dbff6c7febb16844e95a268f7930bdb Mon Sep 17 00:00:00 2001 From: Michael Dawson 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 30136980b..4d0681ac3 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 0c6e64895..9b94a9069 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 5fc752e3a..78c1c9779 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 402c5c91d..dfd7fab26 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)); }); } }