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

Commit 64b4910

Browse files
authored
fix(debugger): Fix issues when calling pause() multiple times (#3501) (#3504)
1 parent 143c710 commit 64b4910

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ chromedriver.log
1111
libpeerconnection.log
1212
xmloutput*
1313
npm-debug.log
14+
.idea/
1415

1516
*.swp
1617
globals.js

lib/browser.ts

+35-14
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,13 @@ export class ProtractorBrowser extends Webdriver {
241241
*/
242242
debuggerServerPort_: number;
243243

244+
/**
245+
* Set to true when we validate that the debug port is open. Since the debug
246+
* port is held open forever once the debugger is attached, it's important
247+
* we only do validation once.
248+
*/
244249
debuggerValidated_: boolean;
245250

246-
247251
/**
248252
* If true, Protractor will interpret any angular apps it comes across as
249253
* hybrid angular1/angular2 apps.
@@ -983,10 +987,12 @@ export class ProtractorBrowser extends Webdriver {
983987
}
984988
});
985989

986-
return doneDeferred.then(null, (err: string) => {
987-
console.error(err);
988-
process.exit(1);
989-
});
990+
return doneDeferred.then(
991+
() => { this.debuggerValidated_ = true; },
992+
(err: string) => {
993+
console.error(err);
994+
process.exit(1);
995+
});
990996
}
991997

992998
private dbgCodeExecutor_: any;
@@ -1043,10 +1049,10 @@ export class ProtractorBrowser extends Webdriver {
10431049

10441050
let browserUnderDebug = this;
10451051
let debuggerReadyPromise = webdriver.promise.defer();
1046-
flow.execute(function() {
1052+
flow.execute(() => {
10471053
process['debugPort'] = opt_debugPort || process['debugPort'];
10481054
browserUnderDebug.validatePortAvailability_(process['debugPort'])
1049-
.then(function(firstTime: boolean) {
1055+
.then((firstTime: boolean) => {
10501056
onStartFn(firstTime);
10511057

10521058
let args = [process.pid, process['debugPort']];
@@ -1056,11 +1062,19 @@ export class ProtractorBrowser extends Webdriver {
10561062
let nodedebug =
10571063
require('child_process').fork(debuggerClientPath, args);
10581064
process.on('exit', function() { nodedebug.kill('SIGTERM'); });
1059-
nodedebug.on('message', function(m: string) {
1060-
if (m === 'ready') {
1061-
debuggerReadyPromise.fulfill();
1062-
}
1063-
});
1065+
nodedebug
1066+
.on('message',
1067+
(m: string) => {
1068+
if (m === 'ready') {
1069+
debuggerReadyPromise.fulfill();
1070+
}
1071+
})
1072+
.on('exit', () => {
1073+
logger.info('Debugger exiting');
1074+
// Clear this so that we know it's ok to attach a debugger
1075+
// again.
1076+
this.dbgCodeExecutor_ = null;
1077+
});
10641078
});
10651079
});
10661080

@@ -1167,6 +1181,8 @@ export class ProtractorBrowser extends Webdriver {
11671181
return this.execPromiseResult_;
11681182
}
11691183
};
1184+
1185+
return pausePromise;
11701186
}
11711187

11721188
/**
@@ -1221,7 +1237,12 @@ export class ProtractorBrowser extends Webdriver {
12211237
* @param {number=} opt_debugPort Optional port to use for the debugging
12221238
* process
12231239
*/
1224-
pause(opt_debugPort?: number) {
1240+
pause(opt_debugPort?: number): webdriver.promise.Promise<any> {
1241+
if (this.dbgCodeExecutor_) {
1242+
logger.info(
1243+
'Encountered browser.pause(), but debugger already attached.');
1244+
return webdriver.promise.fulfilled(true);
1245+
}
12251246
let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js';
12261247
let onStartFn = (firstTime: boolean) => {
12271248
logger.info();
@@ -1240,7 +1261,7 @@ export class ProtractorBrowser extends Webdriver {
12401261
logger.info();
12411262
}
12421263
};
1243-
this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
1264+
return this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
12441265
}
12451266

12461267
/**

lib/debugger/clients/wddebugger.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ WdDebugger.prototype.initRepl_ = function() {
100100
self.replServer.on('exit', function() {
101101
console.log('Resuming code execution');
102102
self.client.req({command: 'disconnect'}, function() {
103-
// Intentionally blank.
103+
process.exit();
104104
});
105105
});
106106
});

0 commit comments

Comments
 (0)