From e003338885a542d5722ca1e729d37fb57998a8a4 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 16 May 2016 13:55:11 -0700 Subject: [PATCH 1/3] 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. --- test/debugger/test-debug-break-on-uncaught.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/test/debugger/test-debug-break-on-uncaught.js b/test/debugger/test-debug-break-on-uncaught.js index 8a5af3abea8a58..79aa4dea897e11 100644 --- a/test/debugger/test-debug-break-on-uncaught.js +++ b/test/debugger/test-debug-break-on-uncaught.js @@ -1,22 +1,22 @@ 'use strict'; -var path = require('path'); -var assert = require('assert'); -var spawn = require('child_process').spawn; -var common = require('../common'); -var debug = require('_debugger'); +const path = require('path'); +const assert = require('assert'); +const spawn = require('child_process').spawn; +const common = require('../common'); +const debug = require('_debugger'); -addScenario('global.js', null, 2); -addScenario('timeout.js', null, 2); +var scenarios = []; + +addScenario('global.js', 2); +addScenario('timeout.js', 2); run(); /***************** IMPLEMENTATION *****************/ -var scenarios; -function addScenario(scriptName, throwsInFile, throwsOnLine) { - if (!scenarios) scenarios = []; +function addScenario(scriptName, throwsOnLine) { scenarios.push( - runScenario.bind(null, scriptName, throwsInFile, throwsOnLine, run) + runScenario.bind(null, scriptName, throwsOnLine, run) ); } @@ -25,10 +25,10 @@ function run() { if (next) next(); } -function runScenario(scriptName, throwsInFile, throwsOnLine, next) { +function runScenario(scriptName, throwsOnLine, next) { console.log('**[ %s ]**', scriptName); var asserted = false; - var port = common.PORT + 1337; + var port = common.PORT; var testScript = path.join( common.fixturesDir, @@ -44,7 +44,12 @@ function runScenario(scriptName, throwsInFile, throwsOnLine, next) { var exceptions = []; - setTimeout(setupClient.bind(null, runTest), 200); + + child.stderr.on('data', (data) => { + if (data.toString().includes('Debugger listening on port')) { + setTimeout(setupClient.bind(null, runTest), 200); + } + }); function setupClient(callback) { var client = new debug.Client(); @@ -88,11 +93,11 @@ function runScenario(scriptName, throwsInFile, throwsOnLine, next) { } function assertHasPaused(client) { + assert(exceptions.length, 'no exceptions thrown, race condition in test?'); assert.equal(exceptions.length, 1, 'debugger did not pause on exception'); assert.equal(exceptions[0].uncaught, true); - assert.equal(exceptions[0].script.name, throwsInFile || testScript); - if (throwsOnLine != null) - assert.equal(exceptions[0].sourceLine + 1, throwsOnLine); + assert.equal(exceptions[0].script.name, testScript); + assert.equal(exceptions[0].sourceLine + 1, throwsOnLine); asserted = true; client.reqContinue(assert.ifError); } From dcf13b2cd35daeced615daf7726cc8bf79cf8a18 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 21 May 2016 15:11:56 -0700 Subject: [PATCH 2/3] squash --- test/debugger/test-debug-break-on-uncaught.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/debugger/test-debug-break-on-uncaught.js b/test/debugger/test-debug-break-on-uncaught.js index 79aa4dea897e11..c6cc93d5a6a2d8 100644 --- a/test/debugger/test-debug-break-on-uncaught.js +++ b/test/debugger/test-debug-break-on-uncaught.js @@ -44,12 +44,17 @@ function runScenario(scriptName, throwsOnLine, next) { var exceptions = []; + var stderr = ''; - child.stderr.on('data', (data) => { - if (data.toString().includes('Debugger listening on port')) { + function stderrListener(data) { + stderr += data.toString(); + if (stderr.includes('Debugger listening on port')) { setTimeout(setupClient.bind(null, runTest), 200); + child.stderr.removeListener('data', stderrListener); } - }); + } + + child.stderr.on('data', stderrListener); function setupClient(callback) { var client = new debug.Client(); From b1eda6b914166f77e21007e4b60ae356be058be3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 22 May 2016 20:53:02 -0700 Subject: [PATCH 3/3] squash: encoding --- test/debugger/test-debug-break-on-uncaught.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/debugger/test-debug-break-on-uncaught.js b/test/debugger/test-debug-break-on-uncaught.js index c6cc93d5a6a2d8..4a63751aaf2857 100644 --- a/test/debugger/test-debug-break-on-uncaught.js +++ b/test/debugger/test-debug-break-on-uncaught.js @@ -47,13 +47,14 @@ function runScenario(scriptName, throwsOnLine, next) { var stderr = ''; function stderrListener(data) { - stderr += data.toString(); + stderr += data; if (stderr.includes('Debugger listening on port')) { setTimeout(setupClient.bind(null, runTest), 200); child.stderr.removeListener('data', stderrListener); } } + child.stderr.setEncoding('utf8'); child.stderr.on('data', stderrListener); function setupClient(callback) {