Skip to content

Commit 7b554b1

Browse files
committed
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: #974 Reviewed-By: Chris Dickinson <[email protected]>
1 parent b150c98 commit 7b554b1

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed
+20-34
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1+
// Flags: --abort_on_uncaught_exception
2+
13
var common = require('../common');
24
var assert = require('assert');
3-
var spawn = require('child_process').spawn;
5+
var domain = require('domain');
46

57
var tests = [
68
nextTick,
79
timer,
810
timerPlusNextTick,
11+
netServer,
912
firstRun,
10-
netServer
11-
]
13+
];
1214

13-
tests.forEach(function(test) {
14-
console.log(test.name);
15-
var child = spawn(process.execPath, [
16-
'--abort-on-uncaught-exception',
17-
'-e',
18-
'(' + test + ')()',
19-
common.PORT
20-
]);
21-
child.stderr.pipe(process.stderr);
22-
child.stdout.pipe(process.stdout);
23-
child.on('exit', function(code) {
24-
assert.strictEqual(code, 0);
25-
});
15+
var errors = 0;
16+
17+
process.on('exit', function() {
18+
assert.equal(errors, tests.length);
2619
});
2720

21+
tests.forEach(function(test) { test(); })
22+
2823
function nextTick() {
29-
var domain = require('domain');
3024
var d = domain.create();
3125

32-
d.on('error', function(err) {
33-
console.log('ok');
34-
process.exit(0);
26+
d.once('error', function(err) {
27+
errors += 1;
3528
});
3629
d.run(function() {
3730
process.nextTick(function() {
@@ -41,12 +34,10 @@ function nextTick() {
4134
}
4235

4336
function timer() {
44-
var domain = require('domain');
4537
var d = domain.create();
4638

4739
d.on('error', function(err) {
48-
console.log('ok');
49-
process.exit(0);
40+
errors += 1;
5041
});
5142
d.run(function() {
5243
setTimeout(function() {
@@ -56,12 +47,10 @@ function timer() {
5647
}
5748

5849
function timerPlusNextTick() {
59-
var domain = require('domain');
6050
var d = domain.create();
6151

6252
d.on('error', function(err) {
63-
console.log('ok');
64-
process.exit(0);
53+
errors += 1;
6554
});
6655
d.run(function() {
6756
setTimeout(function() {
@@ -73,37 +62,34 @@ function timerPlusNextTick() {
7362
}
7463

7564
function firstRun() {
76-
var domain = require('domain');
7765
var d = domain.create();
7866

7967
d.on('error', function(err) {
80-
console.log('ok');
81-
process.exit(0);
68+
errors += 1;
8269
});
8370
d.run(function() {
8471
throw new Error('exceptional!');
8572
});
8673
}
8774

8875
function netServer() {
89-
var domain = require('domain');
9076
var net = require('net');
9177
var d = domain.create();
9278

9379
d.on('error', function(err) {
94-
console.log('ok');
95-
process.exit(0);
80+
errors += 1;
9681
});
9782
d.run(function() {
9883
var server = net.createServer(function(conn) {
9984
conn.pipe(conn);
10085
});
101-
server.listen(Number(process.argv[1]), '0.0.0.0', function() {
102-
var conn = net.connect(Number(process.argv[1]), '0.0.0.0')
86+
server.listen(common.PORT, '0.0.0.0', function() {
87+
var conn = net.connect(common.PORT, '0.0.0.0')
10388
conn.once('data', function() {
10489
throw new Error('ok');
10590
})
10691
conn.end('ok');
92+
server.close();
10793
});
10894
});
10995
}

0 commit comments

Comments
 (0)