Skip to content

Commit

Permalink
no need to erase sims
Browse files Browse the repository at this point in the history
Signed-off-by: Nan Wang <[email protected]>
  • Loading branch information
nanwng committed Aug 29, 2023
1 parent 4ec6bd7 commit 5b7adfe
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
1 change: 0 additions & 1 deletion bp/src/BPSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@
- (BOOL)needsRetry;
- (BPExitStatus)exitStatus;
- (BOOL)isApplicationLaunched;
- (BOOL)shutdownSimulatorWithError:(id *)error;
@end
53 changes: 0 additions & 53 deletions bp/src/BPSimulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ - (NSString *)installApplicationWithHost:(NSString *)testHost withError:(NSError
}];
return nil;
} else {
// [simDevice shutdownWithError:errPtr];
[self shutdownSimulatorWithError:errPtr];
if(*errPtr) {
[BPUtils printInfo:ERROR withString:@"Shutdown simulator failed with error: %@", [*errPtr localizedDescription]];
Expand Down Expand Up @@ -308,47 +307,6 @@ - (BOOL)useSimulatorWithDeviceUDID:(NSUUID *)deviceUDID {
return YES;
}

- (void)eraseSimulator:(SimDevice *)device withError:(id *) error{
NSLog(@"Erasing Simulator %@", device.UDID.UUIDString);
[device eraseContentsAndSettingsWithError:error];
if (*error) {
NSLog(@"Error erasing simulator: %@", *error);
} else {
NSLog(@"Simulator erased successfully.");
}
}

- (BOOL)waitForSimulatorShutdown:(SimDevice *)device {
NSDate *startTime = [NSDate date];
NSTimeInterval timeoutInterval = 30.0;

while (![device.stateString isEqualToString:@"Shutdown"]) {
NSTimeInterval elapsedTime = -[startTime timeIntervalSinceNow];
if (elapsedTime >= timeoutInterval) {
return NO; // Timeout
}

// You might need to add some delay here to avoid busy-waiting
[NSThread sleepForTimeInterval:1.0];
}

return YES; // Successfully shutdown
}

- (void)eraseAndShutdownSimulator:(SimDevice *)device withError: (id *)error {
// Wait for Shutdown
BOOL didShutdown = [self waitForSimulatorShutdown:device];

if (didShutdown) {
NSLog(@"Simulator has been successfully shutdown.");
} else {
NSLog(@"Failed to shutdown simulator within the timeout, erase it.");
// Erase Simulator
[self eraseSimulator:device withError:error];
}
}


- (BOOL)shutdownSimulatorWithError:(id *)error {
[BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", self.device.UDID.UUIDString];

Expand All @@ -359,15 +317,6 @@ - (BOOL)shutdownSimulatorWithError:(id *)error {
return YES;
}

// Xcode 7 has a 'Creating' step that we should wait on before confirming the simulator is ready.
// On many occasions this is the case as we wait for the Simulator to be usable.
if ([self.device.stateString isEqualToString:@"Creating"]) {
[self eraseAndShutdownSimulator:self.device withError:error];
return YES;
}

// The error code for 'Unable to shutdown device in current state: Shutdown'
// can be safely ignored since these codes confirm that the simulator is already shutdown.
return [self.device shutdownWithError:error];
}

Expand All @@ -384,7 +333,6 @@ - (void)openSimulatorHeadlessWithCompletion:(void (^)(NSError *))completion {
[self.device bootAsyncWithOptions:options completionHandler:^(NSError *bootError){
NSError *error = [self waitForDeviceReady];
if (error) {
// [self.device shutdownWithError:&error];
[self shutdownSimulatorWithError:&error];
if (error) {
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
Expand Down Expand Up @@ -636,7 +584,6 @@ - (void)deleteSimulatorWithCompletion:(void (^)(NSError *error, BOOL success))co
}
if (self.device) {
[BPUtils printInfo:INFO withString:@"Shutting down Simulator"];
// [self.device shutdownWithError:&error];
[self shutdownSimulatorWithError:&error];
if (error) {
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
Expand Down

0 comments on commit 5b7adfe

Please sign in to comment.