Skip to content

Commit

Permalink
Create apps on demand rather than at the start of each test
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Nov 13, 2020
1 parent 8641deb commit 1113a24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
1 change: 0 additions & 1 deletion Realm/ObjectServerTests/RLMSyncTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ NS_ASSUME_NONNULL_BEGIN
/// Manually set the refresh token for a user. Used for testing invalid token conditions.
- (void)manuallySetRefreshTokenForUser:(RLMUser *)user value:(NSString *)tokenValue;

- (void)setupSyncManager;
- (void)resetSyncManager;

- (NSString *)badAccessToken;
Expand Down
33 changes: 26 additions & 7 deletions Realm/ObjectServerTests/RLMSyncTestCase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ - (void)sendRequestToServer:(RLMRequest *)request completion:(RLMNetworkTranspor

#pragma mark RLMSyncTestCase

@implementation RLMSyncTestCase
@implementation RLMSyncTestCase {
NSString *_appId;
RLMApp *_app;
}

#pragma mark - Helper methods

Expand Down Expand Up @@ -435,8 +438,9 @@ - (void)manuallySetRefreshTokenForUser:(RLMUser *)user value:(NSString *)tokenVa
- (void)setUp {
[super setUp];
self.continueAfterFailure = NO;

[self setupSyncManager];
if (auto ids = NSProcessInfo.processInfo.environment[@"RLMParentAppIds"]) {
_appIds = [ids componentsSeparatedByString:@","]; //take the one array for split the string
}
}

- (void)tearDown {
Expand All @@ -451,9 +455,6 @@ - (void)setupSyncManager {
NSLog(@"Failed to create app: %@", error);
abort();
}
if (auto ids = NSProcessInfo.processInfo.environment[@"RLMParentAppIds"]) {
_appIds = [ids componentsSeparatedByString:@","]; //take the one array for split the string
}

if (self.isParent) {
[NSFileManager.defaultManager removeItemAtURL:[self clientDataRoot] error:&error];
Expand All @@ -467,8 +468,22 @@ - (void)setupSyncManager {
syncManager.userAgent = self.name;
}

- (NSString *)appId {
if (!_appId) {
[self setupSyncManager];
}
return _appId;
}

- (RLMApp *)app {
if (!_app) {
[self setupSyncManager];
}
return _app;
}

- (void)resetSyncManager {
if (!self.appId) {
if (!_appId) {
return;
}

Expand Down Expand Up @@ -530,4 +545,8 @@ - (NSURL *)clientDataRoot {
return clientDataRoot;
}

- (NSTask *)childTask {
return [self childTaskWithAppIds:_appId ? @[_appId] : @[]];
}

@end
18 changes: 11 additions & 7 deletions Realm/TestUtils/RLMMultiProcessTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ - (NSTask *)childTaskWithAppIds:(NSArray *)appIds {
NSMutableDictionary *env = [NSProcessInfo.processInfo.environment mutableCopy];
env[@"RLMProcessIsChild"] = @"true";
env[@"RLMParentProcessBundleID"] = [NSBundle mainBundle].bundleIdentifier;
if ([self respondsToSelector:@selector(appId)]) {
env[@"RLMParentAppId"] = self.appId;
}

if (appIds.count) {
env[@"RLMParentAppId"] = appIds[0];
env[@"RLMParentAppIds"] = [appIds componentsJoinedByString:@","];
}

Expand Down Expand Up @@ -152,7 +149,7 @@ - (NSTask *)childTask {
return [self childTaskWithAppIds:@[]];
}

- (int)runChildAndWaitWithAppIds:(NSArray *)appIds {
- (NSPipe *)filterPipe {
NSPipe *pipe = [NSPipe pipe];
NSMutableData *buffer = [[NSMutableData alloc] init];

Expand All @@ -173,16 +170,23 @@ - (int)runChildAndWaitWithAppIds:(NSArray *)appIds {
// Remove everything up to the last newline, leaving any data not newline-terminated in the buffer
[buffer replaceBytesInRange:NSMakeRange(0, start - (char *)buffer.bytes) withBytes:0 length:0];
};
return pipe;
}

- (int)runChildAndWaitWithAppIds:(NSArray *)appIds {
NSTask *task = [self childTaskWithAppIds:appIds];
task.standardError = pipe;
task.standardError = self.filterPipe;
[task launch];
[task waitUntilExit];
return task.terminationStatus;
}

- (int)runChildAndWait {
return [self runChildAndWaitWithAppIds:@[]];
NSTask *task = [self childTask];
task.standardError = self.filterPipe;
[task launch];
[task waitUntilExit];
return task.terminationStatus;
}

#else
Expand Down

0 comments on commit 1113a24

Please sign in to comment.