Skip to content

Commit

Permalink
test: don't spawn child processes in domain test
Browse files Browse the repository at this point in the history
Make parallel/test-domain-abort-on-uncaught a little easier to debug,
make it execute the tests in the same process instead of each test in
a separate child process.

PR-URL: #974
Reviewed-By: Chris Dickinson <[email protected]>
  • Loading branch information
bnoordhuis committed Mar 5, 2015
1 parent b150c98 commit 7b554b1
Showing 1 changed file with 20 additions and 34 deletions.
54 changes: 20 additions & 34 deletions test/parallel/test-domain-abort-on-uncaught.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
// Flags: --abort_on_uncaught_exception

var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var domain = require('domain');

var tests = [
nextTick,
timer,
timerPlusNextTick,
netServer,
firstRun,
netServer
]
];

tests.forEach(function(test) {
console.log(test.name);
var child = spawn(process.execPath, [
'--abort-on-uncaught-exception',
'-e',
'(' + test + ')()',
common.PORT
]);
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
child.on('exit', function(code) {
assert.strictEqual(code, 0);
});
var errors = 0;

process.on('exit', function() {
assert.equal(errors, tests.length);
});

tests.forEach(function(test) { test(); })

function nextTick() {
var domain = require('domain');
var d = domain.create();

d.on('error', function(err) {
console.log('ok');
process.exit(0);
d.once('error', function(err) {
errors += 1;
});
d.run(function() {
process.nextTick(function() {
Expand All @@ -41,12 +34,10 @@ function nextTick() {
}

function timer() {
var domain = require('domain');
var d = domain.create();

d.on('error', function(err) {
console.log('ok');
process.exit(0);
errors += 1;
});
d.run(function() {
setTimeout(function() {
Expand All @@ -56,12 +47,10 @@ function timer() {
}

function timerPlusNextTick() {
var domain = require('domain');
var d = domain.create();

d.on('error', function(err) {
console.log('ok');
process.exit(0);
errors += 1;
});
d.run(function() {
setTimeout(function() {
Expand All @@ -73,37 +62,34 @@ function timerPlusNextTick() {
}

function firstRun() {
var domain = require('domain');
var d = domain.create();

d.on('error', function(err) {
console.log('ok');
process.exit(0);
errors += 1;
});
d.run(function() {
throw new Error('exceptional!');
});
}

function netServer() {
var domain = require('domain');
var net = require('net');
var d = domain.create();

d.on('error', function(err) {
console.log('ok');
process.exit(0);
errors += 1;
});
d.run(function() {
var server = net.createServer(function(conn) {
conn.pipe(conn);
});
server.listen(Number(process.argv[1]), '0.0.0.0', function() {
var conn = net.connect(Number(process.argv[1]), '0.0.0.0')
server.listen(common.PORT, '0.0.0.0', function() {
var conn = net.connect(common.PORT, '0.0.0.0')
conn.once('data', function() {
throw new Error('ok');
})
conn.end('ok');
server.close();
});
});
}

0 comments on commit 7b554b1

Please sign in to comment.