Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 252d7d3

Browse files
committed
add
1 parent d671886 commit 252d7d3

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

lib/debugger/debuggerCommons.js

+14-35
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@ exports.attachDebugger = function(pid, opt_port) {
1111
var client = new baseDebugger.Client();
1212
var port = opt_port || process.debugPort;
1313

14-
// Invoke fn if port is available.
15-
var onPortAvailable = function(fn) {
16-
var net = require('net');
17-
var tester = net.connect({port: port}, function() {
18-
console.error('Port ' + port + ' is already in use. Please specify ' +
19-
'another port to debug.');
20-
process.exit(1);
21-
});
22-
tester.once('error', function (err) {
23-
if (err.code === 'ECONNREFUSED') {
24-
tester.once('close', fn).end();
25-
} else {
26-
console.error('Unexpected failure testing for port ' + port + ': ',
27-
err);
28-
process.exit(1);
29-
}
14+
// Call this private function instead of sending SIGUSR1 because Windows.
15+
process._debugProcess(pid);
16+
17+
client.once('ready', function() {
18+
client.setBreakpoint({
19+
type: 'scriptRegExp',
20+
target: '.*executors\.js', //jshint ignore:line
21+
line: 37
22+
}, function() {
23+
client.reqContinue(function() {
24+
// Intentionally blank.
25+
});
3026
});
31-
};
27+
});
3228

3329
// Connect to debugger on port with retry 200ms apart.
3430
var connectWithRetry = function(attempts) {
@@ -43,24 +39,7 @@ exports.attachDebugger = function(pid, opt_port) {
4339
}
4440
});
4541
};
46-
47-
onPortAvailable(function() {
48-
// Call this private function instead of sending SIGUSR1 because Windows.
49-
process._debugProcess(pid);
50-
51-
client.once('ready', function() {
52-
client.setBreakpoint({
53-
type: 'scriptRegExp',
54-
target: '.*executors\.js', //jshint ignore:line
55-
line: 37
56-
}, function() {
57-
client.reqContinue(function() {
58-
// Intentionally blank.
59-
});
60-
});
61-
});
62-
connectWithRetry(10);
63-
});
42+
connectWithRetry(10);
6443

6544
return client;
6645
};

lib/protractor.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,26 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
653653
return asString;
654654
};
655655

656+
// Return a promise that resolves to whether the port is available.
657+
var checkPortAvailability = function(port) {
658+
var net = require('net');
659+
var deferred = webdriver.promise.defer();
660+
var tester = net.connect({port: port}, function() {
661+
deferred.reject('Port ' + port + ' is already in use.');
662+
});
663+
tester.once('error', function (err) {
664+
if (err.code === 'ECONNREFUSED') {
665+
tester.once('close', function() {
666+
deferred.fulfill();
667+
}).end();
668+
} else {
669+
deferred.reject('Unexpected failure testing for port ' + port + ': ' +
670+
err.message);
671+
}
672+
});
673+
return deferred.promise;
674+
};
675+
656676
var vm_ = require('vm');
657677
var browserUnderDebug = this;
658678
var flow = webdriver.promise.controlFlow();
@@ -661,11 +681,13 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
661681
log.puts('Starting WebDriver debugger in a child process. Pause is ' +
662682
'still beta, please report issues at github.com/angular/protractor\n');
663683
process.debugPort = opt_debugPort || process.debugPort;
664-
var nodedebug = require('child_process').
665-
fork(debuggerClientPath, [process.pid, process.debugPort]);
666-
process.on('exit', function() {
667-
nodedebug.kill('SIGTERM');
668-
});
684+
return checkPortAvailability(process.debugPort).then(function() {
685+
var nodedebug = require('child_process').fork(
686+
debuggerClientPath, [process.pid, process.debugPort]);
687+
process.on('exit', function() {
688+
nodedebug.kill('SIGTERM');
689+
});
690+
});
669691
});
670692

671693
var pausePromise = flow.timeout(1000, 'waiting for debugger to attach')

0 commit comments

Comments
 (0)