Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2859f9e

Browse filesBrowse files
committed
test: fix debug-port-cluster flakiness
Rewrite the test so that stderr reordering of the child processes won't confuse the test's expectations. PR-URL: #4310 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 9e1b7aa commit 2859f9e
Copy full SHA for 2859f9e

File tree

Expand file treeCollapse file tree

1 file changed

+13
-35
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-35
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-debug-port-cluster.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-debug-port-cluster.js
+13-35Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,25 @@ var common = require('../common');
33
var assert = require('assert');
44
var spawn = require('child_process').spawn;
55

6-
var port = common.PORT + 1337;
6+
const PORT_MIN = common.PORT + 1337;
7+
const PORT_MAX = PORT_MIN + 2;
78

89
var args = [
9-
'--debug=' + port,
10+
'--debug=' + PORT_MIN,
1011
common.fixturesDir + '/clustered-server/app.js'
1112
];
1213

13-
var child = spawn(process.execPath, args);
14-
var outputLines = [];
14+
const child = spawn(process.execPath, args);
15+
child.stderr.setEncoding('utf8');
1516

16-
child.stderr.on('data', function(data) {
17-
var lines = data.toString().replace(/\r/g, '').trim().split('\n');
18-
var line = lines[0];
19-
20-
lines.forEach(function(ln) { console.log('> ' + ln); } );
21-
22-
if (line === 'all workers are running') {
23-
assertOutputLines();
24-
process.exit();
25-
} else {
26-
outputLines = outputLines.concat(lines);
27-
}
28-
});
29-
30-
process.on('exit', function onExit() {
31-
child.kill();
17+
let stderr = '';
18+
child.stderr.on('data', data => {
19+
stderr += data;
20+
if (child.killed !== true && stderr.includes('all workers are running'))
21+
child.kill();
3222
});
3323

34-
var assertOutputLines = common.mustCall(function() {
35-
var expectedLines = [
36-
'Debugger listening on port ' + port,
37-
'Debugger listening on port ' + (port + 1),
38-
'Debugger listening on port ' + (port + 2),
39-
];
40-
41-
// Do not assume any particular order of output messages,
42-
// since workers can take different amout of time to
43-
// start up
44-
outputLines.sort();
45-
46-
assert.equal(outputLines.length, expectedLines.length);
47-
for (var i = 0; i < expectedLines.length; i++)
48-
assert.equal(outputLines[i], expectedLines[i]);
24+
process.on('exit', () => {
25+
for (let port = PORT_MIN; port <= PORT_MAX; port += 1)
26+
assert(stderr.includes(`Debugger listening on port ${port}`));
4927
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.