From a459f5cc8f68065dd3aaed2a45f775859af36e43 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 20 Jul 2021 15:27:07 -0400 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node-addon-api/pull/1024 Reviewed-By: Chengzhong Wu --- test/common/index.js | 7 +++++++ test/objectwrap_worker_thread.js | 23 ++++++++++++++--------- test/symbol.js | 11 +++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index ab6d12bc8..e8c480cab 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.runTestWithBuildType = 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..e5cfdb81a 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').runTestWithBuildType(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..7601feb2f 100644 --- a/test/symbol.js +++ b/test/symbol.js @@ -3,14 +3,17 @@ 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) +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) {