Skip to content

Commit 5feb88f

Browse files
author
Fatme
authored
Merge pull request #3817 from NativeScript/fatme/debug-timeout-option
Respect timeout option when getting debugger port
2 parents 5fa0308 + 0c9d3e6 commit 5feb88f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IIOSDebuggerPortService {
1717
* Gets iOS debugger port for specified deviceId and appId
1818
* @param {IIOSDebuggerPortInputData} data - Describes deviceId and appId
1919
*/
20-
getPort(data: IIOSDebuggerPortInputData): Promise<number>;
20+
getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise<number>;
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.

lib/services/ios-debug-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
202202
// the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions
203203
// check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
204204
if ((debugOptions.inspector || !debugOptions.client) && this.$hostInfo.isDarwin) {
205-
this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(debugData, device));
205+
this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(device, debugData, debugOptions));
206206
await this.openAppInspector(this._socketProxy.address(), debugData, debugOptions);
207207
return null;
208208
} else {
@@ -211,7 +211,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
211211
}
212212

213213
const deviceIdentifier = device ? device.deviceInfo.identifier : debugData.deviceIdentifier;
214-
this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(debugData, device), deviceIdentifier);
214+
this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(device, debugData, debugOptions), deviceIdentifier);
215215
return this.getChromeDebugUrl(debugOptions, this._socketProxy.options.port);
216216
}
217217
}
@@ -230,9 +230,9 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
230230
}
231231
}
232232

233-
private getSocketFactory(debugData: IDebugData, device?: Mobile.IiOSDevice): () => Promise<net.Socket> {
233+
private getSocketFactory(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): () => Promise<net.Socket> {
234234
const factory = async () => {
235-
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier });
235+
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }, debugOptions);
236236
if (!port) {
237237
this.$errors.fail("NativeScript debugger was not able to get inspector socket port.");
238238
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
1414
private $projectDataService: IProjectDataService,
1515
private $logger: ILogger) { }
1616

17-
public getPort(data: IIOSDebuggerPortInputData): Promise<number> {
17+
public getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise<number> {
1818
return new Promise((resolve, reject) => {
1919
if (!this.canStartLookingForDebuggerPort(data)) {
2020
resolve(IOSDebuggerPortService.DEFAULT_PORT);
2121
return;
2222
}
2323

2424
const key = `${data.deviceId}${data.appId}`;
25-
let retryCount: number = 10;
25+
const timeout = this.getTimeout(debugOptions);
26+
let retryCount = Math.max(timeout * 1000 / 500, 10);
2627

2728
const interval = setInterval(() => {
2829
let port = this.getPortByKey(key);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe("iOSDebuggerPortService", () => {
157157
}
158158

159159
const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir });
160-
clock.tick(10000);
160+
clock.tick(20000);
161161
const port = await promise;
162162
assert.deepEqual(port, testCase.emittedPort);
163163
});
@@ -171,7 +171,7 @@ describe("iOSDebuggerPortService", () => {
171171
}
172172

173173
const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir });
174-
clock.tick(10000);
174+
clock.tick(20000);
175175
const port = await promise;
176176
assert.deepEqual(port, testCase.emittedPort);
177177
});

0 commit comments

Comments
 (0)