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

fix(debugger): Fix issues when calling pause() multiple times (#3501) #3504

Merged
merged 1 commit into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -242,9 +242,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 @@ -979,10 +983,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 @@ -1039,10 +1045,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 @@ -1052,11 +1058,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 @@ -1163,6 +1177,8 @@ export class ProtractorBrowser extends Webdriver {
return this.execPromiseResult_;
}
};

return pausePromise;
}

/**
Expand Down Expand Up @@ -1217,7 +1233,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 @@ -1236,7 +1257,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