Skip to content

Commit 2859f9e

Browse 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 <[email protected]>
1 parent 9e1b7aa commit 2859f9e

File tree

1 file changed

+13
-35
lines changed

1 file changed

+13
-35
lines changed

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

+13-35
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)