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

Commit

Permalink
fix(debugger): Fix issues when calling pause() multiple times (#3501) (
Browse files Browse the repository at this point in the history
  • Loading branch information
heathkit authored Sep 3, 2016
1 parent 143c710 commit 64b4910
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chromedriver.log
libpeerconnection.log
xmloutput*
npm-debug.log
.idea/

*.swp
globals.js
Expand Down
49 changes: 35 additions & 14 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,13 @@ export class ProtractorBrowser extends Webdriver {
*/
debuggerServerPort_: number;

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


/**
* If true, Protractor will interpret any angular apps it comes across as
* hybrid angular1/angular2 apps.
Expand Down Expand Up @@ -983,10 +987,12 @@ export class ProtractorBrowser extends Webdriver {
}
});

return doneDeferred.then(null, (err: string) => {
console.error(err);
process.exit(1);
});
return doneDeferred.then(
() => { this.debuggerValidated_ = true; },
(err: string) => {
console.error(err);
process.exit(1);
});
}

private dbgCodeExecutor_: any;
Expand Down Expand Up @@ -1043,10 +1049,10 @@ export class ProtractorBrowser extends Webdriver {

let browserUnderDebug = this;
let debuggerReadyPromise = webdriver.promise.defer();
flow.execute(function() {
flow.execute(() => {
process['debugPort'] = opt_debugPort || process['debugPort'];
browserUnderDebug.validatePortAvailability_(process['debugPort'])
.then(function(firstTime: boolean) {
.then((firstTime: boolean) => {
onStartFn(firstTime);

let args = [process.pid, process['debugPort']];
Expand All @@ -1056,11 +1062,19 @@ export class ProtractorBrowser extends Webdriver {
let nodedebug =
require('child_process').fork(debuggerClientPath, args);
process.on('exit', function() { nodedebug.kill('SIGTERM'); });
nodedebug.on('message', function(m: string) {
if (m === 'ready') {
debuggerReadyPromise.fulfill();
}
});
nodedebug
.on('message',
(m: string) => {
if (m === 'ready') {
debuggerReadyPromise.fulfill();
}
})
.on('exit', () => {
logger.info('Debugger exiting');
// Clear this so that we know it's ok to attach a debugger
// again.
this.dbgCodeExecutor_ = null;
});
});
});

Expand Down Expand Up @@ -1167,6 +1181,8 @@ export class ProtractorBrowser extends Webdriver {
return this.execPromiseResult_;
}
};

return pausePromise;
}

/**
Expand Down Expand Up @@ -1221,7 +1237,12 @@ export class ProtractorBrowser extends Webdriver {
* @param {number=} opt_debugPort Optional port to use for the debugging
* process
*/
pause(opt_debugPort?: number) {
pause(opt_debugPort?: number): webdriver.promise.Promise<any> {
if (this.dbgCodeExecutor_) {
logger.info(
'Encountered browser.pause(), but debugger already attached.');
return webdriver.promise.fulfilled(true);
}
let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js';
let onStartFn = (firstTime: boolean) => {
logger.info();
Expand All @@ -1240,7 +1261,7 @@ export class ProtractorBrowser extends Webdriver {
logger.info();
}
};
this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
return this.initDebugger_(debuggerClientPath, onStartFn, opt_debugPort);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/debugger/clients/wddebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ WdDebugger.prototype.initRepl_ = function() {
self.replServer.on('exit', function() {
console.log('Resuming code execution');
self.client.req({command: 'disconnect'}, function() {
// Intentionally blank.
process.exit();
});
});
});
Expand Down

0 comments on commit 64b4910

Please sign in to comment.