Permalink
Browse files

test: refactor test-debug-signal-cluster

Notable changes include removing one (but not all) hard-coded ports,
using `common.fail()`, and tidying conditionals and assertions.

PR-URL: #8289
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

 Conflicts:
	test/parallel/test-debug-signal-cluster.js
  • Loading branch information...
Trott authored and Fishrock123 committed Aug 26, 2016
1 parent d2b2abe commit cde0a1edfd198056835f2b9cc452a7f0bcad9227
Showing with 24 additions and 21 deletions.
  1. +8 −7 test/fixtures/clustered-server/app.js
  2. +16 −14 test/parallel/test-debug-signal-cluster.js
@@ -1,12 +1,13 @@
var http = require('http');
var cluster = require('cluster');
var common = require('../../common');
'use strict';
const http = require('http');
const cluster = require('cluster');
function handleRequest(request, response) {
response.end('hello world\n');
}
var NUMBER_OF_WORKERS = 2;
const NUMBER_OF_WORKERS = 2;
var workersOnline = 0;
if (cluster.isMaster) {
@@ -18,7 +19,7 @@ if (cluster.isMaster) {
process.on('message', function(msg) {
if (msg.type === 'getpids') {
var pids = [];
const pids = [];
pids.push(process.pid);
for (var key in cluster.workers)
pids.push(cluster.workers[key].process.pid);
@@ -30,6 +31,6 @@ if (cluster.isMaster) {
cluster.fork();
}
} else {
var server = http.createServer(handleRequest);
server.listen(common.PORT);
const server = http.createServer(handleRequest);
server.listen(0);
}
@@ -1,21 +1,23 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var port = common.PORT + 1; // The fixture uses common.PORT.
var args = ['--debug-port=' + port,
common.fixturesDir + '/clustered-server/app.js'];
var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
var child = spawn(process.execPath, args, options);
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const path = require('path');
var outputLines = [];
const port = common.PORT;
const serverPath = path.join(common.fixturesDir, 'clustered-server', 'app.js');
const args = [`--debug-port=${port}`, serverPath];
const options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
const child = spawn(process.execPath, args, options);
const outputLines = [];
var waitingForDebuggers = false;
var pids = null;
var pids;
child.stderr.on('data', function(data) {
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
const lines = data.toString().replace(/\r/g, '').trim().split('\n');
lines.forEach(function(line) {
console.log('> ' + line);
@@ -40,7 +42,7 @@ child.stderr.on('data', function(data) {
}
});
if (outputLines.length >= expectedLines.length)
if (outputLines.length === expectedLines.length)
onNoMoreLines();
});
@@ -50,7 +52,7 @@ function onNoMoreLines() {
}
setTimeout(function testTimedOut() {
assert(false, 'test timed out.');
common.fail('test timed out');
}, common.platformTimeout(4000)).unref();
process.on('exit', function onExit() {
@@ -61,7 +63,7 @@ process.on('exit', function onExit() {
});
});
var expectedLines = [
const expectedLines = [
'Starting debugger agent.',
'Debugger listening on (\\[::\\]|0\\.0\\.0\\.0):' + (port + 0),
'Starting debugger agent.',

0 comments on commit cde0a1e

Please sign in to comment.