Skip to content

Commit 2a59e4e

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: improve debug-break-on-uncaught reliability
Running the test through CI reveals unreliability due to a race condition. These changes mitigate the race condition, but do not eliminate it. PR-URL: #6793 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Claudio Rodriguez <[email protected]>
1 parent 0013af6 commit 2a59e4e

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

test/debugger/test-debug-break-on-uncaught.js

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
'use strict';
2-
var path = require('path');
3-
var assert = require('assert');
4-
var spawn = require('child_process').spawn;
5-
var common = require('../common');
6-
var debug = require('_debugger');
2+
const path = require('path');
3+
const assert = require('assert');
4+
const spawn = require('child_process').spawn;
5+
const common = require('../common');
6+
const debug = require('_debugger');
77

8-
addScenario('global.js', null, 2);
9-
addScenario('timeout.js', null, 2);
8+
var scenarios = [];
9+
10+
addScenario('global.js', 2);
11+
addScenario('timeout.js', 2);
1012

1113
run();
1214

1315
/***************** IMPLEMENTATION *****************/
1416

15-
var scenarios;
16-
function addScenario(scriptName, throwsInFile, throwsOnLine) {
17-
if (!scenarios) scenarios = [];
17+
function addScenario(scriptName, throwsOnLine) {
1818
scenarios.push(
19-
runScenario.bind(null, scriptName, throwsInFile, throwsOnLine, run)
19+
runScenario.bind(null, scriptName, throwsOnLine, run)
2020
);
2121
}
2222

@@ -25,10 +25,10 @@ function run() {
2525
if (next) next();
2626
}
2727

28-
function runScenario(scriptName, throwsInFile, throwsOnLine, next) {
28+
function runScenario(scriptName, throwsOnLine, next) {
2929
console.log('**[ %s ]**', scriptName);
3030
var asserted = false;
31-
var port = common.PORT + 1337;
31+
var port = common.PORT;
3232

3333
var testScript = path.join(
3434
common.fixturesDir,
@@ -44,7 +44,18 @@ function runScenario(scriptName, throwsInFile, throwsOnLine, next) {
4444

4545
var exceptions = [];
4646

47-
setTimeout(setupClient.bind(null, runTest), 200);
47+
var stderr = '';
48+
49+
function stderrListener(data) {
50+
stderr += data;
51+
if (stderr.includes('Debugger listening on port')) {
52+
setTimeout(setupClient.bind(null, runTest), 200);
53+
child.stderr.removeListener('data', stderrListener);
54+
}
55+
}
56+
57+
child.stderr.setEncoding('utf8');
58+
child.stderr.on('data', stderrListener);
4859

4960
function setupClient(callback) {
5061
var client = new debug.Client();
@@ -88,11 +99,11 @@ function runScenario(scriptName, throwsInFile, throwsOnLine, next) {
8899
}
89100

90101
function assertHasPaused(client) {
102+
assert(exceptions.length, 'no exceptions thrown, race condition in test?');
91103
assert.equal(exceptions.length, 1, 'debugger did not pause on exception');
92104
assert.equal(exceptions[0].uncaught, true);
93-
assert.equal(exceptions[0].script.name, throwsInFile || testScript);
94-
if (throwsOnLine != null)
95-
assert.equal(exceptions[0].sourceLine + 1, throwsOnLine);
105+
assert.equal(exceptions[0].script.name, testScript);
106+
assert.equal(exceptions[0].sourceLine + 1, throwsOnLine);
96107
asserted = true;
97108
client.reqContinue(assert.ifError);
98109
}

0 commit comments

Comments
 (0)