From 8858f5d012c54f1ec624d828b6398e15a3a007a1 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 20 Jul 2021 15:27:07 -0400 Subject: [PATCH 1/4] doc: update tests to avoid running in parallel fixes: https://github.com/nodejs/node-addon-api/issues/1022 The objectwrap_worker_thread and symbol tests were not waiting for the test to complete before the subsequent tests were started. This caused intermitted crashes in the CI. Updated both tests so that they complete before the next test runs. Signed-off-by: Michael Dawson --- test/common/index.js | 7 +++++++ test/objectwrap_worker_thread.js | 23 ++++++++++++++--------- test/symbol.js | 3 +-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index ab6d12bc8..9b98ed531 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -101,3 +101,10 @@ exports.runTestWithBindingPath = async function(test, buildType) { await test(item); } } + +exports.runTestNoBinding = async function(test, buildType) { + buildType = buildType || process.config.target_defaults.default_configuration || 'Release'; + + await Promise.resolve(test(buildType)) + .finally(exports.mustCall()); +} diff --git a/test/objectwrap_worker_thread.js b/test/objectwrap_worker_thread.js index eedc9eeda..ed3ef6889 100644 --- a/test/objectwrap_worker_thread.js +++ b/test/objectwrap_worker_thread.js @@ -1,14 +1,19 @@ 'use strict'; +const path = require('path'); const { Worker, isMainThread, workerData } = require('worker_threads'); -if (isMainThread) { - const buildType = process.config.target_defaults.default_configuration; - new Worker(__filename, { workerData: buildType }); -} else { - const test = binding => { - new binding.objectwrap.Test(); - }; +module.exports = require('./common').runTestNoBinding(test); - const buildType = workerData; - require('./common').runTest(test, buildType); +async function test(buildType) { + if (isMainThread) { + const buildType = process.config.target_defaults.default_configuration; + const worker = new Worker(__filename, { workerData: buildType }); + return new Promise((resolve, reject) => { + worker.on('exit', () => { + resolve(); + }); + }, () => {}); + } else { + await require(path.join(__dirname, 'objectwrap.js')); + } } diff --git a/test/symbol.js b/test/symbol.js index 171f81eb2..fac027020 100644 --- a/test/symbol.js +++ b/test/symbol.js @@ -3,8 +3,7 @@ const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); async function test(binding) From 6bf330b5d361a8fce0a52f079632bef684d37fbc Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 20 Jul 2021 17:12:04 -0400 Subject: [PATCH 2/4] squash: remove unneeded async for symbol test Signed-off-by: Michael Dawson --- test/symbol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/symbol.js b/test/symbol.js index fac027020..fb748e61c 100644 --- a/test/symbol.js +++ b/test/symbol.js @@ -6,7 +6,7 @@ const assert = require('assert'); module.exports = require('./common').runTest(test); -async function test(binding) +function test(binding) { const wellKnownSymbolFunctions = ['asyncIterator','hasInstance','isConcatSpreadable', 'iterator','match','matchAll','replace','search','split','species','toPrimitive','toStringTag','unscopables']; From 3a93f8f798258bd387772c253711828e66f9ba11 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 22 Jul 2021 17:00:03 -0400 Subject: [PATCH 3/4] test: fix the symbol test Only check for the matchAll symbol on 12.x and above Signed-off-by: Michael Dawson --- test/symbol.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/symbol.js b/test/symbol.js index fb748e61c..7601feb2f 100644 --- a/test/symbol.js +++ b/test/symbol.js @@ -8,8 +8,12 @@ module.exports = require('./common').runTest(test); function test(binding) { + const majorNodeVersion = process.versions.node.split('.')[0]; - const wellKnownSymbolFunctions = ['asyncIterator','hasInstance','isConcatSpreadable', 'iterator','match','matchAll','replace','search','split','species','toPrimitive','toStringTag','unscopables']; + let wellKnownSymbolFunctions = ['asyncIterator','hasInstance','isConcatSpreadable', 'iterator','match','replace','search','split','species','toPrimitive','toStringTag','unscopables']; + if (majorNodeVersion >= 12) { + wellKnownSymbolFunctions.push('matchAll'); + } function assertCanCreateSymbol(symbol) { From 817e1a287f133dc1e1dec16dcbd3b3aa38eee6fd Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 22 Jul 2021 17:06:06 -0400 Subject: [PATCH 4/4] squash: address review comments Signed-off-by: Michael Dawson --- test/common/index.js | 2 +- test/objectwrap_worker_thread.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index 9b98ed531..e8c480cab 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -102,7 +102,7 @@ exports.runTestWithBindingPath = async function(test, buildType) { } } -exports.runTestNoBinding = async function(test, buildType) { +exports.runTestWithBuildType = async function(test, buildType) { buildType = buildType || process.config.target_defaults.default_configuration || 'Release'; await Promise.resolve(test(buildType)) diff --git a/test/objectwrap_worker_thread.js b/test/objectwrap_worker_thread.js index ed3ef6889..e5cfdb81a 100644 --- a/test/objectwrap_worker_thread.js +++ b/test/objectwrap_worker_thread.js @@ -2,7 +2,7 @@ const path = require('path'); const { Worker, isMainThread, workerData } = require('worker_threads'); -module.exports = require('./common').runTestNoBinding(test); +module.exports = require('./common').runTestWithBuildType(test); async function test(buildType) { if (isMainThread) {