Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test: Fix debugger repl tests

This makes the output of simple/test-debugger-repl and
simle/test-debugger-repl-utf8 mirror an actual debugger session, so it's
a bit easier to reason about.

Also, it uses the same code for both, and fixes it so that it doesn't
leave zombie processes lying around when it crashes.

Run 1000 times without any failures or zombies.
  • Loading branch information...
commit ec378aaa690dee25b34a696bd893f646ab4616d1 1 parent 57f9f04
@isaacs authored
View
4 test/fixtures/breakpoints_utf8.js
@@ -17,3 +17,7 @@ b();
setInterval(function() {
}, 5000);
+
+
+now = new Date();
+debugger;
View
157 test/simple/test-debugger-repl-utf8.js
@@ -19,162 +19,9 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common');
-var assert = require('assert');
-var spawn = require('child_process').spawn;
-var debug = require('_debugger');
-
-var port = common.PORT + 1337;
-
var script = common.fixturesDir + '/breakpoints_utf8.js';
+process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
-var child = spawn(process.execPath, ['debug', '--port=' + port, script]);
-
-console.error('./node', 'debug', '--port=' + port, script);
-
-var buffer = '';
-child.stdout.setEncoding('utf-8');
-child.stdout.on('data', function(data) {
- data = (buffer + data.toString()).split(/\n/g);
- buffer = data.pop();
- data.forEach(function(line) {
- child.emit('line', line);
- });
-});
-child.stderr.pipe(process.stdout);
-
-var expected = [];
-
-child.on('line', function(line) {
- line = line.replace(/^(debug> )+/, 'debug> ');
- console.error('line> ' + line);
- assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
-
- var expectedLine = expected[0].lines.shift();
- assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine);
-
- if (expected[0].lines.length === 0) {
- var callback = expected[0].callback;
- expected.shift();
- callback && callback();
- }
-});
-
-function addTest(input, output) {
- function next() {
- if (expected.length > 0) {
- child.stdin.write(expected[0].input + '\n');
-
- if (!expected[0].lines) {
- setTimeout(function() {
- var callback = expected[0].callback;
- expected.shift();
-
- callback && callback();
- }, 50);
- }
- } else {
- finish();
- }
- };
- expected.push({input: input, lines: output, callback: next});
-}
-
-// Initial lines
-addTest(null, [
- /listening on port \d+/,
- /connecting... ok/,
- /break in .*:1/,
- /1/, /2/, /3/
-]);
-
-// Next
-addTest('n', [
- /break in .*:11/,
- /9/, /10/, /11/, /12/, /13/
-]);
-
-// Watch
-addTest('watch("\'x\'")');
-
-// Continue
-addTest('c', [
- /break in .*:5/,
- /Watchers/,
- /0:\s+'x' = "x"/,
- /()/,
- /3/, /4/, /5/, /6/, /7/
-]);
-
-// Show watchers
-addTest('watchers', [
- /0:\s+'x' = "x"/
-]);
-
-// Unwatch
-addTest('unwatch("\'x\'")');
-
-// Step out
-addTest('o', [
- /break in .*:12/,
- /10/, /11/, /12/, /13/, /14/
-]);
-
-// Continue
-addTest('c', [
- /break in .*:5/,
- /3/, /4/, /5/, /6/, /7/
-]);
-
-// Set breakpoint by function name
-addTest('sb("setInterval()", "!(setInterval.flag++)")', [
- /1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
-]);
-
-// Continue
-addTest('c', [
- /break in node.js:\d+/,
- /\d/, /\d/, /\d/, /\d/, /\d/
-]);
-
-function finish() {
- process.exit(0);
-}
-
-function quit() {
- if (quit.called) return;
- quit.called = true;
- child.stdin.write('quit');
-}
-
-setTimeout(function() {
- console.error('dying badly');
- var err = 'Timeout';
- if (expected.length > 0 && expected[0].lines) {
- err = err + '. Expected: ' + expected[0].lines.shift();
- }
- quit();
- child.kill('SIGINT');
- child.kill('SIGTERM');
-
- // give the sigkill time to work.
- setTimeout(function() {
- throw new Error(err);
- }, 100);
-
-}, 5000);
-
-process.once('uncaughtException', function(e) {
- quit();
- console.error(e.toString());
- process.exit(1);
-});
+require('./test-debugger-repl.js');
-process.on('exit', function(code) {
- quit();
- if (code === 0) {
- assert.equal(expected.length, 0);
- }
-});
View
99 test/simple/test-debugger-repl.js
@@ -19,7 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var common = require('../common');
var assert = require('assert');
@@ -28,11 +27,10 @@ var debug = require('_debugger');
var port = common.PORT + 1337;
-var script = common.fixturesDir + '/breakpoints.js';
+var script = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
+ common.fixturesDir + '/breakpoints.js';
-var child = spawn(process.execPath, ['debug', '--port=' + port, script], {
- env: { NODE_FORCE_READLINE: 1 }
-});
+var child = spawn(process.execPath, ['debug', '--port=' + port, script]);
console.error('./node', 'debug', '--port=' + port, script);
@@ -45,14 +43,13 @@ child.stdout.on('data', function(data) {
child.emit('line', line);
});
});
-child.stderr.pipe(process.stdout);
+child.stderr.pipe(process.stderr);
var expected = [];
child.on('line', function(line) {
- line = line.replace(/^(debug> )+/, 'debug> ');
- line = line.replace(/\u001b\[\d+\w/g, '');
- console.error('line> ' + line);
+ line = line.replace(/^(debug> *)+/, '');
+ console.log(line);
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
var expectedLine = expected[0].lines.shift();
@@ -68,23 +65,17 @@ child.on('line', function(line) {
function addTest(input, output) {
function next() {
if (expected.length > 0) {
- var res = child.stdin.write(expected[0].input + '\n'),
- callback;
+ console.log('debug> ' + expected[0].input);
+ child.stdin.write(expected[0].input + '\n');
if (!expected[0].lines) {
- callback = expected[0].callback;
+ var callback = expected[0].callback;
expected.shift();
- }
- if (callback) {
- if (res !== true) {
- child.stdin.on('drain', callback);
- } else {
- process.nextTick(callback);
- }
+ callback && callback();
}
} else {
- finish();
+ quit();
}
};
expected.push({input: input, lines: output, callback: next});
@@ -100,17 +91,15 @@ addTest(null, [
// Next
addTest('n', [
- /debug> n/,
/break in .*:11/,
/9/, /10/, /11/, /12/, /13/
]);
// Watch
-addTest('watch("\'x\'"), true', [/debug>/, /true/]);
+addTest('watch("\'x\'")');
// Continue
addTest('c', [
- /debug>/,
/break in .*:5/,
/Watchers/,
/0:\s+'x' = "x"/,
@@ -120,98 +109,76 @@ addTest('c', [
// Show watchers
addTest('watchers', [
- /debug>/,
/0:\s+'x' = "x"/
]);
// Unwatch
-addTest('unwatch("\'x\'"), true', [/debug>/, /true/]);
+addTest('unwatch("\'x\'")');
// Step out
addTest('o', [
- /debug>/,
/break in .*:12/,
/10/, /11/, /12/, /13/, /14/
]);
// Continue
addTest('c', [
- /debug>/,
/break in .*:5/,
/3/, /4/, /5/, /6/, /7/
]);
// Set breakpoint by function name
addTest('sb("setInterval()", "!(setInterval.flag++)")', [
- /debug>/,
/1/, /2/, /3/, /4/, /5/, /6/, /7/, /8/, /9/, /10/
]);
// Continue
addTest('c', [
- /debug>/,
/break in node.js:\d+/,
/\d/, /\d/, /\d/, /\d/, /\d/
]);
-// Repeat last command
-addTest('', [
- /debug>/,
- /break in .*breakpoints.js:\d+/,
- /\d/, /\d/, /\d/, /\d/, /\d/
-]);
-
-addTest('repl', [
- /debug>/,
- /Press Ctrl \+ C to leave debug repl/
-]);
-
-addTest('now', [
- /> now/,
- /\w* \w* \d* \d* \d*:\d*:\d* GMT[+-]\d* (\w*)/
-]);
-
-function finish() {
- // Exit debugger repl
- child.kill('SIGINT');
- child.kill('SIGINT');
+addTest('quit', []);
- // Exit debugger
- child.kill('SIGINT');
- process.exit(0);
-}
+var childClosed = false;
+child.on('close', function(code) {
+ assert(!code);
+ childClosed = true;
+});
+var quitCalled = false;
function quit() {
- if (quit.called) return;
- quit.called = true;
+ if (quitCalled || childClosed) return;
+ quitCalled = true;
child.stdin.write('quit');
+ child.kill('SIGTERM');
}
setTimeout(function() {
+ console.error('dying badly buffer=%j', buffer);
var err = 'Timeout';
if (expected.length > 0 && expected[0].lines) {
err = err + '. Expected: ' + expected[0].lines.shift();
}
- quit();
- child.kill('SIGINT');
- child.kill('SIGTERM');
- // give the sigkill time to work.
- setTimeout(function() {
+ child.on('close', function() {
+ console.error('child is closed');
throw new Error(err);
- }, 100);
+ });
-}, 5000);
+ quit();
+}, 5000).unref();
process.once('uncaughtException', function(e) {
+ console.error('UncaughtException', e, e.stack);
quit();
console.error(e.toString());
process.exit(1);
});
process.on('exit', function(code) {
+ console.error('process exit', code);
quit();
- if (code === 0) {
- assert.equal(expected.length, 0);
- }
+ if (code === 0)
+ assert(childClosed);
});
Please sign in to comment.
Something went wrong with that request. Please try again.