Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #406 from telerik/fatme/timeout-for-debug-command
Browse files Browse the repository at this point in the history
Add timeout option for debug command
  • Loading branch information
Fatme authored and Fatme committed Jul 29, 2015
2 parents b73104b + c0986db commit f34ab7f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 2 additions & 0 deletions bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ $injector.require("devicePlatformsConstants", "./common/mobile/device-platforms-
$injector.require("htmlHelpService", "./common/services/html-help-service");
$injector.requireCommand("dev-preuninstall", "./common/commands/preuninstall");
$injector.requireCommand("doctor", "./common/commands/doctor");

$injector.require("utils", "./common/utils");
5 changes: 5 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,8 @@ interface IDoctorService {
*/
printWarnings(): boolean;
}

interface IUtils {
getParsedTimeout(defaultTimeout: number): number;
getMilliSecondsTimeout(defaultTimeout: number): number;
}
25 changes: 5 additions & 20 deletions mobile/android/android-emulator-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
private $staticConfig: Config.IStaticConfig,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $logcatHelper: Mobile.ILogcatHelper,
private $options: IOptions) {
private $options: IOptions,
private $utils: IUtils) {
iconv.extendNodeEncodings();
this.adbFilePath = this.$staticConfig.getAdbFilePath().wait();
}
Expand Down Expand Up @@ -144,22 +145,6 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
Fiber.yield();
}

private getMilliSecondsTimeout(): number {
let timeout = AndroidEmulatorServices.TIMEOUT_SECONDS;

if(this.$options && this.$options.timeout) {
let parsedValue = parseInt(this.$options.timeout);
if(!isNaN(parsedValue) && parsedValue >= 0) {
timeout = parsedValue;
} else {
this.$logger.info("Specify timeout in a number of seconds to wait. Set it to 0 to wait indefinitely. Default value: " + timeout + " seconds will be used.");
}
}

return timeout * 1000;
}


private getRunningEmulatorId(image: string): IFuture<string> {
return ((): string => {
let runningEmulators = this.getRunningEmulators().wait();
Expand Down Expand Up @@ -231,7 +216,7 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
private startEmulatorInstance(image: string): IFuture<string> {
return (() => {
let emulatorId = this.getRunningEmulatorId(image).wait();
this.endTimeEpoch = helpers.getCurrentEpochTime() + this.getMilliSecondsTimeout();
this.endTimeEpoch = helpers.getCurrentEpochTime() + this.$utils.getMilliSecondsTimeout(AndroidEmulatorServices.TIMEOUT_SECONDS);
if(emulatorId) {
// If there's already a running instance of this image, we'll just deploy the app to it.
return emulatorId;
Expand All @@ -248,7 +233,7 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
{ stdio: "ignore", detached: true }).unref();
}

let isInfiniteWait = this.getMilliSecondsTimeout() === 0;
let isInfiniteWait = this.$utils.getMilliSecondsTimeout(AndroidEmulatorServices.TIMEOUT_SECONDS) === 0;
let hasTimeLeft = helpers.getCurrentEpochTime() < this.endTimeEpoch;

while(hasTimeLeft || isInfiniteWait) {
Expand Down Expand Up @@ -436,7 +421,7 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
return (() => {
this.$logger.printInfoMessageOnSameLine("Waiting for emulator device initialization...");

let isInfiniteWait = this.getMilliSecondsTimeout() === 0;
let isInfiniteWait = this.$utils.getMilliSecondsTimeout(AndroidEmulatorServices.TIMEOUT_SECONDS) === 0;
while(helpers.getCurrentEpochTime() < this.endTimeEpoch || isInfiniteWait) {
let isEmulatorBootCompleted = this.isEmulatorBootCompleted(emulatorId).wait();

Expand Down
27 changes: 27 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
///<reference path="../.d.ts"/>
"use strict";

export class Utils implements IUtils {
constructor(private $options: IOptions,
private $logger: ILogger) { }

public getParsedTimeout(defaultTimeout: number): number {
let timeout = defaultTimeout;
if(this.$options.timeout) {
let parsedValue = parseInt(this.$options.timeout);
if(!isNaN(parsedValue) && parsedValue >= 0) {
timeout = parsedValue;
} else {
this.$logger.info("Specify timeout in a number of seconds to wait. Default value: " + timeout + " seconds will be used.");
}
}

return timeout;
}

public getMilliSecondsTimeout(defaultTimeout: number): number {
let timeout = this.getParsedTimeout(defaultTimeout);
return timeout * 1000;
}
}
$injector.register("utils", Utils);

0 comments on commit f34ab7f

Please sign in to comment.