Skip to content

Commit a368ea6

Browse files
TrottMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e5f4367 commit a368ea6

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

test/fixtures/clustered-server/app.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
var http = require('http');
2-
var cluster = require('cluster');
3-
var common = require('../../common');
1+
'use strict';
2+
3+
const http = require('http');
4+
const cluster = require('cluster');
45

56
function handleRequest(request, response) {
67
response.end('hello world\n');
78
}
89

9-
var NUMBER_OF_WORKERS = 2;
10+
const NUMBER_OF_WORKERS = 2;
1011
var workersOnline = 0;
1112

1213
if (cluster.isMaster) {
@@ -18,7 +19,7 @@ if (cluster.isMaster) {
1819

1920
process.on('message', function(msg) {
2021
if (msg.type === 'getpids') {
21-
var pids = [];
22+
const pids = [];
2223
pids.push(process.pid);
2324
for (var key in cluster.workers)
2425
pids.push(cluster.workers[key].process.pid);
@@ -30,6 +31,6 @@ if (cluster.isMaster) {
3031
cluster.fork();
3132
}
3233
} else {
33-
var server = http.createServer(handleRequest);
34-
server.listen(common.PORT);
34+
const server = http.createServer(handleRequest);
35+
server.listen(0);
3536
}

test/parallel/test-debug-signal-cluster.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var spawn = require('child_process').spawn;
52

6-
var port = common.PORT + 1; // The fixture uses common.PORT.
7-
var args = ['--debug-port=' + port,
8-
common.fixturesDir + '/clustered-server/app.js'];
9-
var options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
10-
var child = spawn(process.execPath, args, options);
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const spawn = require('child_process').spawn;
6+
const path = require('path');
117

12-
var outputLines = [];
8+
const port = common.PORT;
9+
const serverPath = path.join(common.fixturesDir, 'clustered-server', 'app.js');
10+
const args = [`--debug-port=${port}`, serverPath];
11+
const options = { stdio: ['inherit', 'inherit', 'pipe', 'ipc'] };
12+
const child = spawn(process.execPath, args, options);
13+
14+
const outputLines = [];
1315
var waitingForDebuggers = false;
1416

15-
var pids = null;
17+
var pids;
1618

1719
child.stderr.on('data', function(data) {
18-
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
20+
const lines = data.toString().replace(/\r/g, '').trim().split('\n');
1921

2022
lines.forEach(function(line) {
2123
console.log('> ' + line);
@@ -40,7 +42,7 @@ child.stderr.on('data', function(data) {
4042
}
4143

4244
});
43-
if (outputLines.length >= expectedLines.length)
45+
if (outputLines.length === expectedLines.length)
4446
onNoMoreLines();
4547
});
4648

@@ -50,7 +52,7 @@ function onNoMoreLines() {
5052
}
5153

5254
setTimeout(function testTimedOut() {
53-
assert(false, 'test timed out.');
55+
common.fail('test timed out');
5456
}, common.platformTimeout(4000)).unref();
5557

5658
process.on('exit', function onExit() {
@@ -61,7 +63,7 @@ process.on('exit', function onExit() {
6163
});
6264
});
6365

64-
var expectedLines = [
66+
const expectedLines = [
6567
'Starting debugger agent.',
6668
'Debugger listening on port ' + (port + 0),
6769
'Starting debugger agent.',
@@ -77,7 +79,5 @@ function assertOutputLines() {
7779
outputLines.sort();
7880
expectedLines.sort();
7981

80-
assert.equal(outputLines.length, expectedLines.length);
81-
for (var i = 0; i < expectedLines.length; i++)
82-
assert.equal(outputLines[i], expectedLines[i]);
82+
assert.deepStrictEqual(outputLines, expectedLines);
8383
}

0 commit comments

Comments
 (0)