test: refactor test-domain-abort-on-uncaught

* 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: https://github.com/nodejs/node/pull/14541
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
Rich Trott 2017-07-29 21:08:14 -07:00
parent cc43c8fb54
commit 548cc72f66

View File

@ -5,19 +5,16 @@
// setup, the process _does not_ abort. // setup, the process _does not_ abort.
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const domain = require('domain'); const domain = require('domain');
const child_process = require('child_process'); const child_process = require('child_process');
let errorHandlerCalled = false;
const tests = [ const tests = [
function nextTick() { function nextTick() {
const d = domain.create(); const d = domain.create();
d.once('error', function(err) { d.once('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
process.nextTick(function() { process.nextTick(function() {
@ -29,9 +26,7 @@ const tests = [
function timer() { function timer() {
const d = domain.create(); const d = domain.create();
d.on('error', function(err) { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
setTimeout(function() { setTimeout(function() {
@ -43,9 +38,7 @@ const tests = [
function immediate() { function immediate() {
const d = domain.create(); const d = domain.create();
d.on('error', function errorHandler() { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
setImmediate(function() { setImmediate(function() {
@ -57,9 +50,7 @@ const tests = [
function timerPlusNextTick() { function timerPlusNextTick() {
const d = domain.create(); const d = domain.create();
d.on('error', function(err) { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
setTimeout(function() { setTimeout(function() {
@ -73,9 +64,7 @@ const tests = [
function firstRun() { function firstRun() {
const d = domain.create(); const d = domain.create();
d.on('error', function(err) { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
throw new Error('exceptional!'); throw new Error('exceptional!');
@ -85,9 +74,7 @@ const tests = [
function fsAsync() { function fsAsync() {
const d = domain.create(); const d = domain.create();
d.on('error', function errorHandler() { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
const fs = require('fs'); const fs = require('fs');
@ -101,9 +88,7 @@ const tests = [
const net = require('net'); const net = require('net');
const d = domain.create(); const d = domain.create();
d.on('error', function(err) { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
const server = net.createServer(function(conn) { const server = net.createServer(function(conn) {
@ -124,9 +109,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d.on('error', function errorHandler() { d.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -139,9 +122,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d2.on('error', function errorHandler() { d2.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -154,9 +135,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d2.on('error', function errorHandler() { d2.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -172,9 +151,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d2.on('error', function errorHandler() { d2.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -189,9 +166,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d2.on('error', function errorHandler() { d2.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -206,9 +181,7 @@ const tests = [
const d = domain.create(); const d = domain.create();
const d2 = domain.create(); const d2 = domain.create();
d2.on('error', function errorHandler() { d2.on('error', common.mustCall());
errorHandlerCalled = true;
});
d.run(function() { d.run(function() {
d2.run(function() { d2.run(function() {
@ -226,9 +199,6 @@ if (process.argv[2] === 'child') {
tests[testIndex](); tests[testIndex]();
process.on('exit', function onExit() {
assert.strictEqual(errorHandlerCalled, true);
});
} else { } else {
tests.forEach(function(test, testIndex) { tests.forEach(function(test, testIndex) {
@ -242,13 +212,10 @@ if (process.argv[2] === 'child') {
testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception ` + testCmd += `"${process.argv[0]}" --abort-on-uncaught-exception ` +
`"${process.argv[1]}" child ${testIndex}`; `"${process.argv[1]}" child ${testIndex}`;
const child = child_process.exec(testCmd); try {
child_process.execSync(testCmd);
child.on('exit', function onExit(code, signal) { } catch (e) {
assert.strictEqual( assert.fail(`Test index ${testIndex} failed: ${e}`);
code, 0, `Test at index ${testIndex }
} should have exited with exit code 0 but instead exited with code ${
code} and signal ${signal}`);
});
}); });
} }