From 2d2163334d429c2fb5758a4e9966167c959c4d9e Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 13 Jul 2018 17:21:07 +0300 Subject: [PATCH 1/2] Increase the default timeout for debug command from 5 seconds to 10 seconds. Add support for --timeout option that can be passed to debug command. Fix help of debug command. --- docs/man_pages/project/testing/debug-ios.md | 2 +- lib/commands/debug.ts | 4 ++++ lib/common | 2 +- lib/definitions/debug.d.ts | 5 +++++ .../ios-debugger-port-service.d.ts | 5 +++-- lib/definitions/livesync.d.ts | 8 +++++++- lib/helpers/livesync-command-helper.ts | 3 ++- lib/services/ios-debug-service.ts | 2 +- lib/services/ios-debugger-port-service.ts | 20 +++++++++++++++---- lib/services/livesync/ios-livesync-service.ts | 4 ++-- lib/services/livesync/livesync-service.ts | 2 +- lib/services/test-execution-service.ts | 6 ++++-- test/services/ios-debugger-port-service.ts | 4 ++-- 13 files changed, 49 insertions(+), 18 deletions(-) diff --git a/docs/man_pages/project/testing/debug-ios.md b/docs/man_pages/project/testing/debug-ios.md index d257e6f953..f2b296db5f 100644 --- a/docs/man_pages/project/testing/debug-ios.md +++ b/docs/man_pages/project/testing/debug-ios.md @@ -27,7 +27,7 @@ While debugging, prints the output from the application in the console and watch * `--debug-brk` - Prepares, builds and deploys the application package on a device or in a simulator, runs the app, launches the developer tools of your Safari browser and stops at the first code statement. * `--start` - Attaches the debug tools to a deployed and running app and launches the developer tools of your Safari browser. * `--no-client` - If set, the NativeScript CLI attaches the debug tools but does not launch the developer tools in Safari. Could be used on already started Safari Web Inspector. -* `--timeout` - Sets the number of seconds that NativeScript CLI will wait for the simulator/device to boot. If not set, the default timeout is 90 seconds. +* `--timeout` - Sets the number of seconds that NativeScript CLI will wait to find the inspector socket port from device's logs. If not set, the default timeout is 10 seconds. * `--no-watch` - If set, changes in your code will not be reflected during the execution of this command. * `--clean` - If set, forces rebuilding the native application. * `--chrome` - Deprecated - default behavior uses '--chrome' implicitly. Allows debugging in Chrome Developer Tools. If set, Safari Web Inspector is not started and debugging is attached to Chrome Developer Tools. diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index d11de92990..5f97432bd1 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -159,6 +159,10 @@ export class DebugIOSCommand implements ICommand { this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`); } + if (this.$options.timeout && !parseInt(this.$options.timeout, 10)) { + this.$errors.fail(`Timeout option specifies the seconds NativeScript CLI will wait to find the inspector socket port from device's logs. Must be a number.`); + } + return await this.debugPlatformCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS); } diff --git a/lib/common b/lib/common index b8ec069f9c..bf13c6c8ec 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit b8ec069f9ce1722129a8e2f05892e58e6b04bab4 +Subproject commit bf13c6c8ecea6f9b6b519b033c16281201244521 diff --git a/lib/definitions/debug.d.ts b/lib/definitions/debug.d.ts index 6254473cbf..b977308e76 100644 --- a/lib/definitions/debug.d.ts +++ b/lib/definitions/debug.d.ts @@ -86,6 +86,11 @@ interface IDebugOptions { * Defines if should print all availableDevices */ availableDevices?: boolean; + /** + * Defines the timeout in seconds {N} CLI will wait to find the inspector socket port from device's logs. + * If not provided, defaults to 10 seconds. + */ + timeout?: string; } /** diff --git a/lib/definitions/ios-debugger-port-service.d.ts b/lib/definitions/ios-debugger-port-service.d.ts index f4fecdfcea..50f156afb0 100644 --- a/lib/definitions/ios-debugger-port-service.d.ts +++ b/lib/definitions/ios-debugger-port-service.d.ts @@ -21,10 +21,11 @@ interface IIOSDebuggerPortService { /** * Attaches on DEBUGGER_PORT_FOUND event and STARTING_IOS_APPLICATION events * In case when DEBUGGER_PORT_FOUND event is emitted, stores the port and clears the timeout if such. - * In case when STARTING_IOS_APPLICATION event is emitted, sets the port to null and add timeout for 5000 miliseconds which checks if port is null and prints a warning. + * In case when STARTING_IOS_APPLICATION event is emitted, sets the port to null and add timeout for 10000 miliseconds which checks if port is null and prints a warning. * @param {Mobile.IDevice} device - Describes the device which logs should be parsed. * @param {IProjectDir} data - Object that has a projectDir property. + * @param {IDebugOptions} debugOptions * @returns {Promise} */ - attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): Promise; + attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir, debugOptions: IDebugOptions): Promise; } \ No newline at end of file diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index c4a21e6106..82d70d7958 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -159,6 +159,12 @@ interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOp * Forces a build before the initial livesync. */ clean?: boolean; + + /** + * Defines the timeout in seconds {N} CLI will wait to find the inspector socket port from device's logs. + * If not provided, defaults to 10seconds. + */ + timeout: string; } interface ILatestAppPackageInstalledSettings extends IDictionary> { /* empty */ } @@ -337,7 +343,7 @@ interface IPlatformLiveSyncService { fullSync(syncInfo: IFullSyncInfo): Promise; liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise; refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise; - prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): Promise; + prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo, debugOptions: IDebugOptions): Promise; } interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase { diff --git a/lib/helpers/livesync-command-helper.ts b/lib/helpers/livesync-command-helper.ts index 45a674f13d..e97073ad42 100644 --- a/lib/helpers/livesync-command-helper.ts +++ b/lib/helpers/livesync-command-helper.ts @@ -109,7 +109,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { clean: this.$options.clean, bundle: !!this.$options.bundle, release: this.$options.release, - env: this.$options.env + env: this.$options.env, + timeout: this.$options.timeout }; await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo); diff --git a/lib/services/ios-debug-service.ts b/lib/services/ios-debug-service.ts index 401e2f6507..2fbb2c4691 100644 --- a/lib/services/ios-debug-service.ts +++ b/lib/services/ios-debug-service.ts @@ -63,7 +63,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS await this.device.openDeviceLogStream(); } - await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData); + await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData, debugOptions); if (debugOptions.emulator) { if (debugOptions.start) { diff --git a/lib/services/ios-debugger-port-service.ts b/lib/services/ios-debugger-port-service.ts index ed6c574be6..04995e9f48 100644 --- a/lib/services/ios-debugger-port-service.ts +++ b/lib/services/ios-debugger-port-service.ts @@ -6,6 +6,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { private mapDebuggerPortData: IDictionary = {}; private static DEFAULT_PORT = 18181; private static MIN_REQUIRED_FRAMEWORK_VERSION = "4.0.1"; + private static DEFAULT_TIMEOUT_IN_SECONDS = 10; constructor(private $iOSLogParserService: IIOSLogParserService, private $iOSProjectService: IPlatformProjectService, @@ -36,14 +37,14 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { }); } - public async attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): Promise { + public async attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir, debugOptions: IDebugOptions): Promise { const projectData = this.$projectDataService.getProjectData(data && data.projectDir); if (!this.canStartLookingForDebuggerPort(projectData)) { return; } this.attachToDebuggerPortFoundEventCore(); - this.attachToAttachRequestEvent(device); + this.attachToAttachRequestEvent(device, debugOptions); await this.$iOSLogParserService.startParsingLog(device, projectData); } @@ -64,7 +65,9 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { } @cache() - private attachToAttachRequestEvent(device: Mobile.IDevice): void { + private attachToAttachRequestEvent(device: Mobile.IDevice, debugOptions: IDebugOptions): void { + const timeout = this.getTimeout(debugOptions); + this.$iOSNotification.on(ATTACH_REQUEST_EVENT_NAME, (data: IIOSDebuggerPortData) => { this.$logger.trace(ATTACH_REQUEST_EVENT_NAME, data); const timer = setTimeout(() => { @@ -72,7 +75,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { if (!this.getPortByKey(`${data.deviceId}${data.appId}`)) { this.$logger.warn(`NativeScript debugger was not able to get inspector socket port on device ${data.deviceId} for application ${data.appId}.`); } - }, 5000); + }, timeout * 1000); this.setData(data, { port: null, timer }); }); @@ -103,5 +106,14 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { clearTimeout(storedData.timer); } } + + private getTimeout(debugOptions: IDebugOptions): number { + let timeout = parseInt(debugOptions && debugOptions.timeout, 10); + if (!timeout) { + timeout = IOSDebuggerPortService.DEFAULT_TIMEOUT_IN_SECONDS; + } + + return timeout; + } } $injector.register("iOSDebuggerPortService", IOSDebuggerPortService); diff --git a/lib/services/livesync/ios-livesync-service.ts b/lib/services/livesync/ios-livesync-service.ts index 3e902407d8..32503cbee6 100644 --- a/lib/services/livesync/ios-livesync-service.ts +++ b/lib/services/livesync/ios-livesync-service.ts @@ -66,9 +66,9 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I } } - public async prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): Promise { + public async prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo, debugOptions: IDebugOptions): Promise { if (!liveSyncInfo.skipWatcher) { - return this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, data); + return this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, data, debugOptions); } } diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 5b1589380d..9306894704 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -459,7 +459,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi const platformLiveSyncService = this.getLiveSyncService(platform); const deviceBuildInfoDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier); - await platformLiveSyncService.prepareForLiveSync(device, projectData, liveSyncData); + await platformLiveSyncService.prepareForLiveSync(device, projectData, liveSyncData, deviceBuildInfoDescriptor.debugOptions); await this.ensureLatestAppPackageIsInstalledOnDevice({ device, diff --git a/lib/services/test-execution-service.ts b/lib/services/test-execution-service.ts index 8105310c29..01ca5af753 100644 --- a/lib/services/test-execution-service.ts +++ b/lib/services/test-execution-service.ts @@ -125,7 +125,8 @@ class TestExecutionService implements ITestExecutionService { watchAllFiles: this.$options.syncAllFiles, bundle: !!this.$options.bundle, release: this.$options.release, - env: this.$options.env + env: this.$options.env, + timeout: this.$options.timeout }; await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo); @@ -253,7 +254,8 @@ class TestExecutionService implements ITestExecutionService { watchAllFiles: this.$options.syncAllFiles, bundle: !!this.$options.bundle, release: this.$options.release, - env: this.$options.env + env: this.$options.env, + timeout: this.$options.timeout }; await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo); diff --git a/test/services/ios-debugger-port-service.ts b/test/services/ios-debugger-port-service.ts index 3dd8fd2a3f..765d255d11 100644 --- a/test/services/ios-debugger-port-service.ts +++ b/test/services/ios-debugger-port-service.ts @@ -148,7 +148,7 @@ describe("iOSDebuggerPortService", () => { _.each(testCases, testCase => { it(testCase.name, async () => { - await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj); + await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj, {}); if (testCase.emitStartingIOSApplicationEvent) { emitStartingIOSApplicationEvent(); } @@ -162,7 +162,7 @@ describe("iOSDebuggerPortService", () => { assert.deepEqual(port, testCase.emittedPort); }); it(`${testCase.name} for multiline debugger port message.`, async () => { - await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj); + await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj, {}); if (testCase.emitStartingIOSApplicationEvent) { emitStartingIOSApplicationEvent(); } From 62b01ddfeef96d1487142e9503b5995449512c06 Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 17 Jul 2018 08:39:08 +0300 Subject: [PATCH 2/2] Support for --timeout 0 --- lib/commands/debug.ts | 20 +++++++++++++++++++- lib/common | 2 +- lib/services/ios-debugger-port-service.ts | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 5f97432bd1..6a239677f9 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -159,13 +159,31 @@ export class DebugIOSCommand implements ICommand { this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`); } - if (this.$options.timeout && !parseInt(this.$options.timeout, 10)) { + const isValidTimeoutOption = this.isValidTimeoutOption(); + if (!isValidTimeoutOption) { this.$errors.fail(`Timeout option specifies the seconds NativeScript CLI will wait to find the inspector socket port from device's logs. Must be a number.`); } return await this.debugPlatformCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS); } + private isValidTimeoutOption() { + if (!this.$options.timeout) { + return true; + } + + const timeout = parseInt(this.$options.timeout, 10); + if (timeout === 0) { + return true; + } + + if (!timeout) { + return false; + } + + return true; + } + public platform = this.$devicePlatformsConstants.iOS; } diff --git a/lib/common b/lib/common index bf13c6c8ec..31b4d8d779 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit bf13c6c8ecea6f9b6b519b033c16281201244521 +Subproject commit 31b4d8d779e754d72d750658df8def9345ae0bf2 diff --git a/lib/services/ios-debugger-port-service.ts b/lib/services/ios-debugger-port-service.ts index 04995e9f48..e16ae3e41e 100644 --- a/lib/services/ios-debugger-port-service.ts +++ b/lib/services/ios-debugger-port-service.ts @@ -109,6 +109,9 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService { private getTimeout(debugOptions: IDebugOptions): number { let timeout = parseInt(debugOptions && debugOptions.timeout, 10); + if (timeout === 0) { + timeout = Number.MAX_SAFE_INTEGER; + } if (!timeout) { timeout = IOSDebuggerPortService.DEFAULT_TIMEOUT_IN_SECONDS; }