Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
debug: connect after child is ready
Browse files Browse the repository at this point in the history
We now wait to connect to the debuggee until we know that its error
stream has data, to ensure that the output message "connecting..... ok"
appears after "Debugger listening on port xyz"

I also increased the test timeout to let the more complex tests finish
in time on Windows

This change fixes the following unit tests on Windows:
 test-debugger-repl.js
 test-debugger-repl-term.js
 test-debugger-repl-utf8.js
 test-debugger-repl-restart.js
  • Loading branch information
orangemocha authored and trevnorris committed Dec 6, 2013
1 parent 1903240 commit 6e33718
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions lib/_debugger.js
Expand Up @@ -25,6 +25,7 @@ var util = require('util'),
vm = require('vm'),
repl = require('repl'),
inherits = util.inherits,
assert = require('assert'),
spawn = require('child_process').spawn;

exports.start = function(argv, stdin, stdout) {
Expand Down Expand Up @@ -1612,6 +1613,7 @@ Interface.prototype.trySpawn = function(cb) {
childArgs = this.args;

this.killChild();
assert(!this.child);

if (this.args.length === 2) {
var match = this.args[1].match(/^([^:]+):(\d+)$/);
Expand Down Expand Up @@ -1647,12 +1649,10 @@ Interface.prototype.trySpawn = function(cb) {
}
}

if (!this.child) {
this.child = spawn(process.execPath, childArgs);
this.child = spawn(process.execPath, childArgs);

this.child.stdout.on('data', this.childPrint.bind(this));
this.child.stderr.on('data', this.childPrint.bind(this));
}
this.child.stdout.on('data', this.childPrint.bind(this));
this.child.stderr.on('data', this.childPrint.bind(this));

this.pause();

Expand Down Expand Up @@ -1709,8 +1709,10 @@ Interface.prototype.trySpawn = function(cb) {
client.connect(port, host);
}

setTimeout(function() {
self.print('connecting to port ' + port + '..', true);
attemptConnect();
}, 50);
this.child.stderr.once('data', function() {
setImmediate(function() {
self.print('connecting to port ' + port + '..', true);
attemptConnect();
});
});
};
2 changes: 1 addition & 1 deletion test/simple/helper-debugger-repl.js
Expand Up @@ -91,7 +91,7 @@ function startDebugger(scriptToDebug) {
});

quit();
}, 5000).unref();
}, 10000).unref();

process.once('uncaughtException', function(e) {
console.error('UncaughtException', e, e.stack);
Expand Down

0 comments on commit 6e33718

Please sign in to comment.