Skip to content

Respect timeout option when getting debugger port #3817

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 2 commits into from
Aug 14, 2018
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
2 changes: 1 addition & 1 deletion lib/definitions/ios-debugger-port-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IIOSDebuggerPortService {
* Gets iOS debugger port for specified deviceId and appId
* @param {IIOSDebuggerPortInputData} data - Describes deviceId and appId
*/
getPort(data: IIOSDebuggerPortInputData): Promise<number>;
getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise<number>;
/**
* 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.
Expand Down
8 changes: 4 additions & 4 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
// the VSCode Ext starts `tns debug ios --no-client` to start/attach to debug sessions
// check if --no-client is passed - default to opening a tcp socket (versus Chrome DevTools (websocket))
if ((debugOptions.inspector || !debugOptions.client) && this.$hostInfo.isDarwin) {
this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(debugData, device));
this._socketProxy = await this.$socketProxyFactory.createTCPSocketProxy(this.getSocketFactory(device, debugData, debugOptions));
await this.openAppInspector(this._socketProxy.address(), debugData, debugOptions);
return null;
} else {
Expand All @@ -211,7 +211,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
}

const deviceIdentifier = device ? device.deviceInfo.identifier : debugData.deviceIdentifier;
this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(debugData, device), deviceIdentifier);
this._socketProxy = await this.$socketProxyFactory.createWebSocketProxy(this.getSocketFactory(device, debugData, debugOptions), deviceIdentifier);
return this.getChromeDebugUrl(debugOptions, this._socketProxy.options.port);
}
}
Expand All @@ -230,9 +230,9 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
}
}

private getSocketFactory(debugData: IDebugData, device?: Mobile.IiOSDevice): () => Promise<net.Socket> {
private getSocketFactory(device: Mobile.IiOSDevice, debugData: IDebugData, debugOptions: IDebugOptions): () => Promise<net.Socket> {
const factory = async () => {
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier });
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: debugData.projectDir, deviceId: debugData.deviceIdentifier, appId: debugData.applicationIdentifier }, debugOptions);
if (!port) {
this.$errors.fail("NativeScript debugger was not able to get inspector socket port.");
}
Expand Down
5 changes: 3 additions & 2 deletions lib/services/ios-debugger-port-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export class IOSDebuggerPortService implements IIOSDebuggerPortService {
private $projectDataService: IProjectDataService,
private $logger: ILogger) { }

public getPort(data: IIOSDebuggerPortInputData): Promise<number> {
public getPort(data: IIOSDebuggerPortInputData, debugOptions?: IDebugOptions): Promise<number> {
return new Promise((resolve, reject) => {
if (!this.canStartLookingForDebuggerPort(data)) {
resolve(IOSDebuggerPortService.DEFAULT_PORT);
return;
}

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

const interval = setInterval(() => {
let port = this.getPortByKey(key);
Expand Down
4 changes: 2 additions & 2 deletions test/services/ios-debugger-port-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("iOSDebuggerPortService", () => {
}

const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir });
clock.tick(10000);
clock.tick(20000);
const port = await promise;
assert.deepEqual(port, testCase.emittedPort);
});
Expand All @@ -171,7 +171,7 @@ describe("iOSDebuggerPortService", () => {
}

const promise = iOSDebuggerPortService.getPort({ deviceId: deviceId, appId: appId, projectDir: mockProjectDirObj.projectDir });
clock.tick(10000);
clock.tick(20000);
const port = await promise;
assert.deepEqual(port, testCase.emittedPort);
});
Expand Down