Skip to content

Commit 0d56983

Browse files
authored
Try to handle the hang-after-timeout issue #38 (#40)
- Ensure the runner remains around for the lifetime of the launch application block - Add more logging around killing the app in the simulator in case the above fix doesn't do anything
1 parent 2d0781b commit 0d56983

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ - (void)stopTestsWithErrorMessage:(NSString *)message forTestName:(NSString *)te
211211
if (![[self.device stateString] isEqualToString:@"Shutdown"]) {
212212
// self.appPID can be zero when running the parsing tests
213213
// since we're not actually creating a simulator and running an app.
214+
[BPUtils printInfo:ERROR withString:@"Will kill the process with appPID: %d", self.appPID];
214215
if (self.appPID && (kill(self.appPID, 0) == 0) && (kill(self.appPID, SIGTERM) < 0)) {
216+
[BPUtils printInfo:ERROR withString:@"Failed to kill the process with appPID: %d", self.appPID];
215217
perror("kill");
218+
} else {
219+
[BPUtils printInfo:ERROR withString:@"Success killing the process with appPID: %d", self.appPID];
216220
}
217221
}
218222

Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,21 @@ - (void)launchApplicationAndExecuteTestsWithParser:(BPTreeParser *)parser andCom
276276
self.monitor.hostBundleId = hostBundleId;
277277
parser.delegate = self.monitor;
278278

279+
// Keep the simulator runner around through processing of the block
280+
__block typeof(self) blockSelf = self;
281+
279282
[self.device launchApplicationAsyncWithID:hostBundleId options:options completionHandler:^(NSError *error, pid_t pid) {
283+
// Save the process ID to the monitor
284+
blockSelf.monitor.appPID = pid;
285+
280286
if (error == nil) {
281287
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
282288
dispatch_source_set_event_handler(source, ^{
283289
dispatch_source_cancel(source);
284290
});
285-
__block __weak SimulatorRunner *weakSelf = self;
286-
weakSelf.monitor.appPID = pid;
287291
dispatch_source_set_cancel_handler(source, ^{
288292
// Post a APPCLOSED signal to the fifo
289-
[weakSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]];
293+
[blockSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]];
290294
});
291295
dispatch_resume(source);
292296
self.stdOutHandle.readabilityHandler = ^(NSFileHandle *handle) {

0 commit comments

Comments
 (0)