Skip to content

Commit

Permalink
doc: update tests to avoid running in parallel
Browse files Browse the repository at this point in the history
fixes: nodejs/node-addon-api#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 <[email protected]>

PR-URL: nodejs/node-addon-api#1024
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
kevindavies8 committed Jul 27, 2021
1 parent 06c4faf commit 5f07939
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
7 changes: 7 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
23 changes: 14 additions & 9 deletions test/objectwrap_worker_thread.js
Original file line number Diff line number Diff line change
@@ -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'));
}
}
11 changes: 7 additions & 4 deletions test/symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 5f07939

Please sign in to comment.