Skip to content

Add timeout option to debug command #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2015
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
7 changes: 4 additions & 3 deletions lib/services/android-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AndroidDebugService implements IDebugService {
private $hostInfo: IHostInfo,
private $errors: IErrors,
private $opener: IOpener,
private $staticConfig: IStaticConfig) { }
private $staticConfig: IStaticConfig,
private $utils: IUtils) { }

private get platform() { return "android"; }

Expand Down Expand Up @@ -195,8 +196,8 @@ class AndroidDebugService implements IDebugService {
private startAndGetPort(packageName: string): IFuture<number> {
return (() => {
let port = -1;
let timeout = 60;

let timeout = this.$utils.getParsedTimeout(60);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab/space isssue maybe

let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
let envDebugInFullpath = packageDir + AndroidDebugService.ENV_DEBUG_IN_FILENAME;
this.device.adb.executeShellCommand(`rm "${envDebugInFullpath}"`).wait();
Expand Down
33 changes: 26 additions & 7 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function connectEventually(factory: () => net.Socket, handler: (socket: net.Sock
}

class IOSDebugService implements IDebugService {
private static TIMEOUT_SECONDS = 60;

constructor(
private $platformService: IPlatformService,
private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices,
Expand All @@ -73,16 +75,22 @@ class IOSDebugService implements IDebugService {
private $injector: IInjector,
private $npmInstallationManager: INpmInstallationManager,
private $options: IOptions,
private $projectDataService: IProjectDataService) { }
private $projectDataService: IProjectDataService,
private $utils: IUtils) { }

get platform(): string {
return "ios";
}

public debug(): IFuture<void> {
if ((!this.$options.debugBrk && !this.$options.start) || (this.$options.debugBrk && this.$options.start)) {
if (this.$options.debugBrk && this.$options.start) {
this.$errors.failWithoutHelp("Expected exactly one of the --debug-brk or --start options.");
}

if(!this.$options.debugBrk && !this.$options.start) {
this.$logger.warn("Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk.");
this.$options.debugBrk = true;
}

if (this.$options.emulator) {
if (this.$options.debugBrk) {
Expand Down Expand Up @@ -137,12 +145,14 @@ class IOSDebugService implements IDebugService {
let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector);

try {
awaitNotification(npc, notification.appLaunching(projectId), 60000).wait();
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
awaitNotification(npc, notification.appLaunching(projectId), timeout).wait();
process.nextTick(() => {
npc.postNotificationAndAttachForData(notification.waitForDebug(projectId));
npc.postNotificationAndAttachForData(notification.attachRequest(projectId));
});
awaitNotification(npc, notification.readyForAttach(projectId), 5000).wait();

awaitNotification(npc, notification.readyForAttach(projectId), this.getReadyForAttachTimeout(timeout)).wait();
} catch(e) {
this.$logger.trace(`Timeout error: ${e}`);
this.$errors.failWithoutHelp("Timeout waiting for NativeScript debugger.");
Expand All @@ -163,11 +173,12 @@ class IOSDebugService implements IDebugService {
let projectId = this.$projectData.projectId;
let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector);

let timeout = this.getReadyForAttachTimeout();
let [alreadyConnected, readyForAttach, attachAvailable] = [
notification.alreadyConnected(projectId),
notification.readyForAttach(projectId),
notification.attachAvailable(projectId)
].map((notification) => awaitNotification(npc, notification, 2000));
].map((notification) => awaitNotification(npc, notification, timeout));

npc.postNotificationAndAttachForData(notification.attachAvailabilityQuery(projectId));

Expand All @@ -183,7 +194,7 @@ class IOSDebugService implements IDebugService {
this.$errors.failWithoutHelp("A debugger is already connected.");
case attachAvailable:
process.nextTick(() => npc.postNotificationAndAttachForData(notification.attachRequest(projectId)));
try { awaitNotification(npc, notification.readyForAttach(projectId), 2000).wait(); }
try { awaitNotification(npc, notification.readyForAttach(projectId), timeout).wait(); }
catch (e) {
this.$errors.failWithoutHelp(`The application ${projectId} timed out when performing the NativeScript debugger handshake.`);
}
Expand Down Expand Up @@ -244,6 +255,14 @@ class IOSDebugService implements IDebugService {
return inspectorPath;
}).future<string>()();
}


private getReadyForAttachTimeout(timeoutInMilliseconds?: number): number {
let timeout = timeoutInMilliseconds || this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
let readyForAttachTimeout = timeout / 10 ;
let defaultReadyForAttachTimeout = 5000;
return readyForAttachTimeout > defaultReadyForAttachTimeout ? readyForAttachTimeout : defaultReadyForAttachTimeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Math.max here

}
}
$injector.register("iOSDebugService", IOSDebugService);

Expand Down Expand Up @@ -306,7 +325,7 @@ function awaitNotification(npc: iOSProxyServices.NotificationProxyClient, notifi

let timeoutObject = setTimeout(() => {
detachObserver();
future.throw(new Error("Timeout receiving notification."));
future.throw(new Error(`Timeout receiving ${notification} notification.`));
}, timeout);

function notificationObserver(notification: string) {
Expand Down