Skip to content

Commit 5ae0031

Browse files
author
Dimitar Tachev
authored
Merge pull request #117 from telerik/tachev/fix-stop-application
fix: stop the application using the local pid instead of `simctl terminate` (the terminate commands hangs when the application is on a breakpoint)
2 parents 85c4666 + 5393c98 commit 5ae0031

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

lib/declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface ISimulator extends INameGetter {
5252
installApplication(deviceId: string, applicationPath: string): Promise<void>;
5353
uninstallApplication(deviceId: string, appIdentifier: string): Promise<void>;
5454
startApplication(deviceId: string, appIdentifier: string, options: IOptions): Promise<string>;
55-
stopApplication(deviceId: string, appIdentifier: string, bundleExecutable: string): Promise<string>;
55+
stopApplication(deviceId: string, appIdentifier: string, bundleExecutable: string): Promise<void>;
5656
getDeviceLogProcess(deviceId: string): Promise<any>;
5757
startSimulator(options: IOptions, device?: IDevice): Promise<void>;
5858
}

lib/iphone-simulator-xcode-simctl.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,24 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
9393
return launchResult;
9494
}
9595

96-
public async stopApplication(deviceId: string, appIdentifier: string, bundleExecutable: string): Promise<string> {
96+
public async stopApplication(deviceId: string, appIdentifier: string, bundleExecutable: string): Promise<void> {
9797
try {
98-
let xcodeMajorVersion: number = null;
99-
try {
100-
const xcodeVersion = xcode.getXcodeVersionData();
101-
xcodeMajorVersion = +xcodeVersion.major;
102-
} catch (err) {
103-
// Ignore the error.
104-
}
105-
106-
let resultOfTermination: string;
107-
if (xcodeMajorVersion && xcodeMajorVersion < 8) {
108-
// Xcode 7.x does not have support for `xcrun simctl terminate` command
109-
resultOfTermination = childProcess.execSync(`killall ${bundleExecutable}`, { skipError: true });
110-
} else {
111-
resultOfTermination = await this.simctl.terminate(deviceId, appIdentifier);
98+
let pid = this.getPid(deviceId, bundleExecutable);
99+
while (pid) {
100+
childProcess.execSync(`kill -9 ${pid}`, { skipError: true });
101+
pid = this.getPid(deviceId, bundleExecutable);
102+
if (pid) {
103+
utils.sleep(0.1);
104+
}
112105
}
113-
114-
// killall command does not terminate the processes immediately and we have to wait a little bit,
115-
// just to ensure all related processes and services are dead.
116-
// Same is valid for simctl terminate when Simulator's OS version is below 10.
117-
utils.sleep(0.5);
118-
119-
return resultOfTermination;
120106
} catch (e) {
121107
}
122108
}
123109

110+
private getPid(deviceId: string, bundleExecutable: string): string {
111+
return childProcess.execSync(`ps -ef | grep ${bundleExecutable} | grep ${deviceId} | grep -v grep | awk '{print $2}'`, { skipError: true }).toString().trim();
112+
}
113+
124114
public async getDeviceLogProcess(deviceId: string, predicate?: string): Promise<child_process.ChildProcess> {
125115
const device = await this.getDeviceFromIdentifier(deviceId);
126116
return new Promise<child_process.ChildProcess>((resolve, reject) => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {
@@ -44,4 +44,4 @@
4444
"engines": {
4545
"node": ">=4.2.1 <5.0.0 || >=5.1.0 <11.0.0"
4646
}
47-
}
47+
}

0 commit comments

Comments
 (0)