Browse Source

test: don't call process.exit() in debugger tests

process.exit() tends to hide bugs, both in tests and node.js.
Rewrite the tests so that the event loop exits naturally.
v0.11.8-release
Ben Noordhuis 11 years ago
parent
commit
81655a224a
  1. 11
      test/fixtures/clustered-server/app.js
  2. 14
      test/simple/test-debug-cluster.js
  3. 13
      test/simple/test-debug-port-cluster.js

11
test/fixtures/clustered-server/app.js

@ -11,10 +11,13 @@ var workersOnline = 0;
if (cluster.isMaster) {
cluster.on('online', function() {
workersOnline++;
if (workersOnline == NUMBER_OF_WORKERS)
console.error('all workers are running');
});
if (++workersOnline === NUMBER_OF_WORKERS) {
console.error('all workers are running');
for (var key in cluster.workers) {
cluster.workers[key].disconnect();
}
}
});
for (var i = 0; i < NUMBER_OF_WORKERS; i++) {
cluster.fork();

14
test/simple/test-debug-cluster.js

@ -27,7 +27,6 @@ var args = ['--debug', common.fixturesDir + '/clustered-server/app.js' ];
var child = spawn(process.execPath, args);
var outputLines = [];
child.stderr.on('data', function(data) {
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
var line = lines[0];
@ -36,21 +35,12 @@ child.stderr.on('data', function(data) {
if (line === 'all workers are running') {
assertOutputLines();
process.exit();
} else {
outputLines = outputLines.concat(lines);
}
});
setTimeout(function testTimedOut() {
assert(false, 'test timed out.');
}, 3000);
process.on('exit', function() {
child.kill();
});
function assertOutputLines() {
var assertOutputLines = common.mustCall(function() {
var expectedLines = [
'debugger listening on port ' + 5858,
'debugger listening on port ' + 5859,
@ -65,4 +55,4 @@ function assertOutputLines() {
assert.equal(outputLines.length, expectedLines.length)
for (var i = 0; i < expectedLines.length; i++)
assert.equal(outputLines[i], expectedLines[i]);
}
});

13
test/simple/test-debug-port-cluster.js

@ -41,21 +41,12 @@ child.stderr.on('data', function(data) {
if (line === 'all workers are running') {
assertOutputLines();
process.exit();
} else {
outputLines = outputLines.concat(lines);
}
});
setTimeout(function testTimedOut() {
assert(false, 'test timed out.');
}, 3000);
process.on('exit', function() {
child.kill();
});
function assertOutputLines() {
var assertOutputLines = common.mustCall(function() {
var expectedLines = [
'debugger listening on port ' + port,
'debugger listening on port ' + (port+1),
@ -70,4 +61,4 @@ function assertOutputLines() {
assert.equal(outputLines.length, expectedLines.length)
for (var i = 0; i < expectedLines.length; i++)
assert.equal(outputLines[i], expectedLines[i]);
}
});

Loading…
Cancel
Save