node/test/parallel/test-domain-abort-on-uncaught.js
Ben Noordhuis 7b554b1a8f test: don't spawn child processes in domain test
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: https://github.com/iojs/io.js/pull/974
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-03-05 20:08:56 +01:00

96 lines
1.7 KiB
JavaScript

// Flags: --abort_on_uncaught_exception
var common = require('../common');
var assert = require('assert');
var domain = require('domain');
var tests = [
nextTick,
timer,
timerPlusNextTick,
netServer,
firstRun,
];
var errors = 0;
process.on('exit', function() {
assert.equal(errors, tests.length);
});
tests.forEach(function(test) { test(); })
function nextTick() {
var d = domain.create();
d.once('error', function(err) {
errors += 1;
});
d.run(function() {
process.nextTick(function() {
throw new Error('exceptional!');
});
});
}
function timer() {
var d = domain.create();
d.on('error', function(err) {
errors += 1;
});
d.run(function() {
setTimeout(function() {
throw new Error('exceptional!');
}, 33);
});
}
function timerPlusNextTick() {
var d = domain.create();
d.on('error', function(err) {
errors += 1;
});
d.run(function() {
setTimeout(function() {
process.nextTick(function() {
throw new Error('exceptional!');
});
}, 33);
});
}
function firstRun() {
var d = domain.create();
d.on('error', function(err) {
errors += 1;
});
d.run(function() {
throw new Error('exceptional!');
});
}
function netServer() {
var net = require('net');
var d = domain.create();
d.on('error', function(err) {
errors += 1;
});
d.run(function() {
var server = net.createServer(function(conn) {
conn.pipe(conn);
});
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();
});
});
}