Skip to content

Commit 7d31fe9

Browse files
author
Fatme
authored
Merge pull request #3752 from NativeScript/fatme/timeout-debug
Increase the default timeout for debug command from 5 to 10 seconds
2 parents 5488cb6 + 62b01dd commit 7d31fe9

13 files changed

+70
-18
lines changed

docs/man_pages/project/testing/debug-ios.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ While debugging, prints the output from the application in the console and watch
2727
* `--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.
2828
* `--start` - Attaches the debug tools to a deployed and running app and launches the developer tools of your Safari browser.
2929
* `--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.
30-
* `--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.
30+
* `--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.
3131
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
3232
* `--clean` - If set, forces rebuilding the native application.
3333
* `--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.

lib/commands/debug.ts

+22
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,31 @@ export class DebugIOSCommand implements ICommand {
159159
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
160160
}
161161

162+
const isValidTimeoutOption = this.isValidTimeoutOption();
163+
if (!isValidTimeoutOption) {
164+
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.`);
165+
}
166+
162167
return await this.debugPlatformCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
163168
}
164169

170+
private isValidTimeoutOption() {
171+
if (!this.$options.timeout) {
172+
return true;
173+
}
174+
175+
const timeout = parseInt(this.$options.timeout, 10);
176+
if (timeout === 0) {
177+
return true;
178+
}
179+
180+
if (!timeout) {
181+
return false;
182+
}
183+
184+
return true;
185+
}
186+
165187
public platform = this.$devicePlatformsConstants.iOS;
166188
}
167189

lib/definitions/debug.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ interface IDebugOptions {
8686
* Defines if should print all availableDevices
8787
*/
8888
availableDevices?: boolean;
89+
/**
90+
* Defines the timeout in seconds {N} CLI will wait to find the inspector socket port from device's logs.
91+
* If not provided, defaults to 10 seconds.
92+
*/
93+
timeout?: string;
8994
}
9095

9196
/**

lib/definitions/ios-debugger-port-service.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ interface IIOSDebuggerPortService {
2121
/**
2222
* Attaches on DEBUGGER_PORT_FOUND event and STARTING_IOS_APPLICATION events
2323
* In case when DEBUGGER_PORT_FOUND event is emitted, stores the port and clears the timeout if such.
24-
* 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.
24+
* 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.
2525
* @param {Mobile.IDevice} device - Describes the device which logs should be parsed.
2626
* @param {IProjectDir} data - Object that has a projectDir property.
27+
* @param {IDebugOptions} debugOptions
2728
* @returns {Promise<void>}
2829
*/
29-
attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): Promise<void>;
30+
attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir, debugOptions: IDebugOptions): Promise<void>;
3031
}

lib/definitions/livesync.d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOp
159159
* Forces a build before the initial livesync.
160160
*/
161161
clean?: boolean;
162+
163+
/**
164+
* Defines the timeout in seconds {N} CLI will wait to find the inspector socket port from device's logs.
165+
* If not provided, defaults to 10seconds.
166+
*/
167+
timeout: string;
162168
}
163169

164170
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
@@ -337,7 +343,7 @@ interface IPlatformLiveSyncService {
337343
fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo>;
338344
liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo>;
339345
refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
340-
prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): Promise<void>;
346+
prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo, debugOptions: IDebugOptions): Promise<void>;
341347
}
342348

343349
interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {

lib/helpers/livesync-command-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
109109
clean: this.$options.clean,
110110
bundle: !!this.$options.bundle,
111111
release: this.$options.release,
112-
env: this.$options.env
112+
env: this.$options.env,
113+
timeout: this.$options.timeout
113114
};
114115

115116
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);

lib/services/ios-debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
6363
await this.device.openDeviceLogStream();
6464
}
6565

66-
await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData);
66+
await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData, debugOptions);
6767

6868
if (debugOptions.emulator) {
6969
if (debugOptions.start) {

lib/services/ios-debugger-port-service.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
66
private mapDebuggerPortData: IDictionary<IIOSDebuggerPortStoredData> = {};
77
private static DEFAULT_PORT = 18181;
88
private static MIN_REQUIRED_FRAMEWORK_VERSION = "4.0.1";
9+
private static DEFAULT_TIMEOUT_IN_SECONDS = 10;
910

1011
constructor(private $iOSLogParserService: IIOSLogParserService,
1112
private $iOSProjectService: IPlatformProjectService,
@@ -36,14 +37,14 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
3637
});
3738
}
3839

39-
public async attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir): Promise<void> {
40+
public async attachToDebuggerPortFoundEvent(device: Mobile.IDevice, data: IProjectDir, debugOptions: IDebugOptions): Promise<void> {
4041
const projectData = this.$projectDataService.getProjectData(data && data.projectDir);
4142
if (!this.canStartLookingForDebuggerPort(projectData)) {
4243
return;
4344
}
4445

4546
this.attachToDebuggerPortFoundEventCore();
46-
this.attachToAttachRequestEvent(device);
47+
this.attachToAttachRequestEvent(device, debugOptions);
4748

4849
await this.$iOSLogParserService.startParsingLog(device, projectData);
4950
}
@@ -64,15 +65,17 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
6465
}
6566

6667
@cache()
67-
private attachToAttachRequestEvent(device: Mobile.IDevice): void {
68+
private attachToAttachRequestEvent(device: Mobile.IDevice, debugOptions: IDebugOptions): void {
69+
const timeout = this.getTimeout(debugOptions);
70+
6871
this.$iOSNotification.on(ATTACH_REQUEST_EVENT_NAME, (data: IIOSDebuggerPortData) => {
6972
this.$logger.trace(ATTACH_REQUEST_EVENT_NAME, data);
7073
const timer = setTimeout(() => {
7174
this.clearTimeout(data);
7275
if (!this.getPortByKey(`${data.deviceId}${data.appId}`)) {
7376
this.$logger.warn(`NativeScript debugger was not able to get inspector socket port on device ${data.deviceId} for application ${data.appId}.`);
7477
}
75-
}, 5000);
78+
}, timeout * 1000);
7679

7780
this.setData(data, { port: null, timer });
7881
});
@@ -103,5 +106,17 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
103106
clearTimeout(storedData.timer);
104107
}
105108
}
109+
110+
private getTimeout(debugOptions: IDebugOptions): number {
111+
let timeout = parseInt(debugOptions && debugOptions.timeout, 10);
112+
if (timeout === 0) {
113+
timeout = Number.MAX_SAFE_INTEGER;
114+
}
115+
if (!timeout) {
116+
timeout = IOSDebuggerPortService.DEFAULT_TIMEOUT_IN_SECONDS;
117+
}
118+
119+
return timeout;
120+
}
106121
}
107122
$injector.register("iOSDebuggerPortService", IOSDebuggerPortService);

lib/services/livesync/ios-livesync-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
6666
}
6767
}
6868

69-
public async prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo): Promise<void> {
69+
public async prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo, debugOptions: IDebugOptions): Promise<void> {
7070
if (!liveSyncInfo.skipWatcher) {
71-
return this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, data);
71+
return this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, data, debugOptions);
7272
}
7373
}
7474

lib/services/livesync/livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
459459
const platformLiveSyncService = this.getLiveSyncService(platform);
460460
const deviceBuildInfoDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
461461

462-
await platformLiveSyncService.prepareForLiveSync(device, projectData, liveSyncData);
462+
await platformLiveSyncService.prepareForLiveSync(device, projectData, liveSyncData, deviceBuildInfoDescriptor.debugOptions);
463463

464464
await this.ensureLatestAppPackageIsInstalledOnDevice({
465465
device,

lib/services/test-execution-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class TestExecutionService implements ITestExecutionService {
124124
watchAllFiles: this.$options.syncAllFiles,
125125
bundle: !!this.$options.bundle,
126126
release: this.$options.release,
127-
env: this.$options.env
127+
env: this.$options.env,
128+
timeout: this.$options.timeout
128129
};
129130

130131
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
@@ -251,7 +252,8 @@ class TestExecutionService implements ITestExecutionService {
251252
watchAllFiles: this.$options.syncAllFiles,
252253
bundle: !!this.$options.bundle,
253254
release: this.$options.release,
254-
env: this.$options.env
255+
env: this.$options.env,
256+
timeout: this.$options.timeout
255257
};
256258

257259
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);

test/services/ios-debugger-port-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe("iOSDebuggerPortService", () => {
148148

149149
_.each(testCases, testCase => {
150150
it(testCase.name, async () => {
151-
await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj);
151+
await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj, <any>{});
152152
if (testCase.emitStartingIOSApplicationEvent) {
153153
emitStartingIOSApplicationEvent();
154154
}
@@ -162,7 +162,7 @@ describe("iOSDebuggerPortService", () => {
162162
assert.deepEqual(port, testCase.emittedPort);
163163
});
164164
it(`${testCase.name} for multiline debugger port message.`, async () => {
165-
await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj);
165+
await iOSDebuggerPortService.attachToDebuggerPortFoundEvent(device, mockProjectDirObj, <any>{});
166166
if (testCase.emitStartingIOSApplicationEvent) {
167167
emitStartingIOSApplicationEvent();
168168
}

0 commit comments

Comments
 (0)