Skip to content
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

Try to handle the hang-after-timeout issue #38 #40

Merged
merged 1 commit into from
Jan 27, 2017
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
4 changes: 4 additions & 0 deletions Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ - (void)stopTestsWithErrorMessage:(NSString *)message forTestName:(NSString *)te
if (![[self.device stateString] isEqualToString:@"Shutdown"]) {
// self.appPID can be zero when running the parsing tests
// since we're not actually creating a simulator and running an app.
[BPUtils printInfo:ERROR withString:@"Will kill the process with appPID: %d", self.appPID];
if (self.appPID && (kill(self.appPID, 0) == 0) && (kill(self.appPID, SIGTERM) < 0)) {
[BPUtils printInfo:ERROR withString:@"Failed to kill the process with appPID: %d", self.appPID];
perror("kill");
} else {
[BPUtils printInfo:ERROR withString:@"Success killing the process with appPID: %d", self.appPID];
}
}

Expand Down
10 changes: 7 additions & 3 deletions Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,21 @@ - (void)launchApplicationAndExecuteTestsWithParser:(BPTreeParser *)parser andCom
self.monitor.hostBundleId = hostBundleId;
parser.delegate = self.monitor;

// Keep the simulator runner around through processing of the block
__block typeof(self) blockSelf = self;

[self.device launchApplicationAsyncWithID:hostBundleId options:options completionHandler:^(NSError *error, pid_t pid) {
// Save the process ID to the monitor
blockSelf.monitor.appPID = pid;

if (error == nil) {
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
dispatch_source_set_event_handler(source, ^{
dispatch_source_cancel(source);
});
__block __weak SimulatorRunner *weakSelf = self;
weakSelf.monitor.appPID = pid;
dispatch_source_set_cancel_handler(source, ^{
// Post a APPCLOSED signal to the fifo
[weakSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]];
[blockSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]];
});
dispatch_resume(source);
self.stdOutHandle.readabilityHandler = ^(NSFileHandle *handle) {
Expand Down