Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport debugger test fixes v6.x #11184

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions test/debugger/test-debug-break-on-uncaught.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function runScenario(scriptName, throwsOnLine, next) {
client.connect(port);
}

let interval;
function runTest(client) {
client.req(
{
Expand All @@ -91,19 +92,22 @@ function runScenario(scriptName, throwsOnLine, next) {

client.reqContinue(function(error) {
assert.ifError(error);
setTimeout(assertHasPaused.bind(null, client), 100);
interval = setInterval(assertHasPaused.bind(null, client), 10);
});
}
);
}

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, testScript);
assert.equal(exceptions[0].sourceLine + 1, throwsOnLine);
if (!exceptions.length) return;

assert.strictEqual(exceptions.length, 1,
'debugger did not pause on exception');
assert.strictEqual(exceptions[0].uncaught, true);
assert.strictEqual(exceptions[0].script.name, testScript);
assert.strictEqual(exceptions[0].sourceLine + 1, throwsOnLine);
asserted = true;
client.reqContinue(assert.ifError);
clearInterval(interval);
}
}
20 changes: 10 additions & 10 deletions test/debugger/test-debugger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ setTimeout(function() {

var resCount = 0;
var p = new debug.Protocol();
p.onResponse = function(res) {
p.onResponse = function() {
resCount++;
};

Expand Down Expand Up @@ -89,7 +89,7 @@ function addTest(cb) {
addTest(function(client, done) {
console.error('requesting version');
client.reqVersion(function(err, v) {
assert.ok(!err);
assert.ifError(err);
console.log('version: %s', v);
assert.strictEqual(process.versions.v8, v);
done();
Expand All @@ -99,13 +99,13 @@ addTest(function(client, done) {
addTest(function(client, done) {
console.error('requesting scripts');
client.reqScripts(function(err) {
assert.ok(!err);
assert.ifError(err);
console.error('got %d scripts', Object.keys(client.scripts).length);

var foundMainScript = false;
for (var k in client.scripts) {
var script = client.scripts[k];
if (script && script.name === 'node.js') {
if (script && script.name === 'bootstrap_node.js') {
foundMainScript = true;
break;
}
Expand All @@ -119,7 +119,7 @@ addTest(function(client, done) {
console.error('eval 2+2');
client.reqEval('2+2', function(err, res) {
console.error(res);
assert.ok(!err);
assert.ifError(err);
assert.strictEqual(res.text, '4');
assert.strictEqual(res.value, 4);
done();
Expand All @@ -137,7 +137,7 @@ function doTest(cb, done) {
var args = ['--debug=' + debugPort, '-e', script];
nodeProcess = spawn(process.execPath, args);

nodeProcess.stdout.once('data', function(c) {
nodeProcess.stdout.once('data', function() {
console.log('>>> new node process: %d', nodeProcess.pid);
var failed = true;
try {
Expand All @@ -158,7 +158,7 @@ function doTest(cb, done) {
console.error('got stderr data %j', data);
nodeProcess.stderr.resume();
b += data;
if (didTryConnect === false && b.match(/Debugger listening on port/)) {
if (didTryConnect === false && b.match(/Debugger listening on /)) {
didTryConnect = true;

// The timeout is here to expose a race in the bootstrap process.
Expand All @@ -168,10 +168,10 @@ function doTest(cb, done) {

function tryConnect() {
// Wait for some data before trying to connect
var c = new debug.Client();
const c = new debug.Client();
console.error('>>> connecting...');
c.connect(debug.port);
c.on('break', function(brk) {
c.on('break', function() {
c.reqContinue(function() {});
});
c.on('ready', function() {
Expand Down Expand Up @@ -199,7 +199,7 @@ function doTest(cb, done) {


function run() {
var t = tests[0];
const t = tests[0];
if (!t) return;

doTest(t, function() {
Expand Down
52 changes: 31 additions & 21 deletions test/debugger/test-debugger-remote.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const path = require('path');

var buffer = '';
var scriptToDebug = common.fixturesDir + '/empty.js';

function fail() {
assert(0); // `--debug-brk script.js` should not quit
}
const PORT = common.PORT;
const scriptToDebug = path.join(common.fixturesDir, 'empty.js');

// running with debug agent
var child = spawn(process.execPath, ['--debug-brk=5959', scriptToDebug]);

console.error(process.execPath, '--debug-brk=5959', scriptToDebug);
const child = spawn(process.execPath, [`--debug-brk=${PORT}`, scriptToDebug]);

// connect to debug agent
var interfacer = spawn(process.execPath, ['debug', 'localhost:5959']);

console.error(process.execPath, 'debug', 'localhost:5959');
const interfacer = spawn(process.execPath, ['debug', `localhost:${PORT}`]);
interfacer.stdout.setEncoding('utf-8');

// fail the test if either of the processes exit normally
const debugBreakExit = common.fail.bind(null, 'child should not exit normally');
const debugExit = common.fail.bind(null, 'interfacer should not exit normally');
child.on('exit', debugBreakExit);
interfacer.on('exit', debugExit);

let buffer = '';
const expected = [
`\bconnecting to localhost:${PORT} ... ok`,
'\bbreak in test/fixtures/empty.js:2'
];
const actual = [];
interfacer.stdout.on('data', function(data) {
data = (buffer + data).split('\n');
buffer = data.pop();
Expand All @@ -30,22 +36,26 @@ interfacer.stdout.on('data', function(data) {

interfacer.on('line', function(line) {
line = line.replace(/^(debug> *)+/, '');
console.log(line);
var expected = '\bconnecting to localhost:5959 ... ok';
assert.ok(expected == line, 'Got unexpected line: ' + line);
if (expected.includes(line)) {
actual.push(line);
}
});

// allow time to start up the debugger
setTimeout(function() {
child.removeListener('exit', fail);
// remove the exit handlers before killing the processes
child.removeListener('exit', debugBreakExit);
interfacer.removeListener('exit', debugExit);

child.kill();
interfacer.removeListener('exit', fail);
interfacer.kill();
}, 2000);
}, common.platformTimeout(2000));

process.on('exit', function() {
// additional checks to ensure that both the processes were actually killed
assert(child.killed);
assert(interfacer.killed);
assert.deepStrictEqual(actual, expected);
});

interfacer.stderr.pipe(process.stderr);
4 changes: 2 additions & 2 deletions test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
var common = require('../common');
var repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');
Expand Down Expand Up @@ -57,7 +57,7 @@ addTest('c', [

// Execute
addTest('exec process.title', [
/node/
common.isFreeBSD || common.isOSX || common.isLinux ? /node/ : ''
]);

// Execute
Expand Down