Skip to content

Commit

Permalink
test: refactor test-domain-abort-on-uncaught
Browse files Browse the repository at this point in the history
* use common.mustCall() instead of exit handler
* use execSync instead of exec so test is reliable under load
* move from sequential to parallel

PR-URL: #14541
Fixes: #11826
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Sep 5, 2017
1 parent 4b9de44 commit 2ce80d9
Showing 1 changed file with 19 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
// setup, the process _does not_ abort.

const common = require('../common');

const assert = require('assert');
const domain = require('domain');
const child_process = require('child_process');

let errorHandlerCalled = false;

const tests = [
function nextTick() {
const d = domain.create();

d.once('error', function(err) {
errorHandlerCalled = true;
});
d.once('error', common.mustCall());

d.run(function() {
process.nextTick(function() {
Expand All @@ -29,9 +26,7 @@ const tests = [
function timer() {
const d = domain.create();

d.on('error', function(err) {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
setTimeout(function() {
Expand All @@ -43,9 +38,7 @@ const tests = [
function immediate() {
const d = domain.create();

d.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
setImmediate(function() {
Expand All @@ -57,9 +50,7 @@ const tests = [
function timerPlusNextTick() {
const d = domain.create();

d.on('error', function(err) {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
setTimeout(function() {
Expand All @@ -73,9 +64,7 @@ const tests = [
function firstRun() {
const d = domain.create();

d.on('error', function(err) {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
throw new Error('exceptional!');
Expand All @@ -85,9 +74,7 @@ const tests = [
function fsAsync() {
const d = domain.create();

d.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
const fs = require('fs');
Expand All @@ -101,9 +88,7 @@ const tests = [
const net = require('net');
const d = domain.create();

d.on('error', function(err) {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
const server = net.createServer(function(conn) {
Expand All @@ -124,9 +109,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -139,9 +122,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d2.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d2.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -154,9 +135,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d2.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d2.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -172,9 +151,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d2.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d2.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -189,9 +166,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d2.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d2.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -206,9 +181,7 @@ const tests = [
const d = domain.create();
const d2 = domain.create();

d2.on('error', function errorHandler() {
errorHandlerCalled = true;
});
d2.on('error', common.mustCall());

d.run(function() {
d2.run(function() {
Expand All @@ -226,9 +199,6 @@ if (process.argv[2] === 'child') {

tests[testIndex]();

process.on('exit', function onExit() {
assert.strictEqual(errorHandlerCalled, true);
});
} else {

tests.forEach(function(test, testIndex) {
Expand All @@ -242,13 +212,10 @@ if (process.argv[2] === 'child') {
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception ` +
`"${process.argv[1]}" child ${testIndex}`;

const child = child_process.exec(testCmd);

child.on('exit', function onExit(code, signal) {
assert.strictEqual(
code, 0, `Test at index ${testIndex
} should have exited with exit code 0 but instead exited with code ${
code} and signal ${signal}`);
});
try {
child_process.execSync(testCmd);
} catch (e) {
assert.fail(undefined, undefined, `Test index ${testIndex} failed: ${e}`);
}
});
}

0 comments on commit 2ce80d9

Please sign in to comment.