Skip to content

Commit

Permalink
Flexible Sync API v2(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsflax authored and dianaafanador3 committed Apr 22, 2022
1 parent 7d72714 commit 2430945
Show file tree
Hide file tree
Showing 17 changed files with 1,728 additions and 1,276 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ identifier_name:
- _rlmSetAccessor(_:)
- _rlmSetProperty(_:_:_:)
- _rlmType
- _rlmSyncSubscription
- id
- pk
- to
Expand Down
2 changes: 1 addition & 1 deletion Realm/ObjectServerTests/RLMSyncTestCase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ - (NSString *)flexibleSyncAppId {
}
else {
NSError *error;
_flexibleSyncAppId = [RealmServer.shared createAppWithQueryableFields:@[@"age", @"breed", @"partition", @"firstName", @"boolCol", @"intCol", @"stringCol", @"dateCol", @"lastName"] error:&error];
_flexibleSyncAppId = [RealmServer.shared createAppWithQueryableFields:@[@"age", @"breed", @"partition", @"firstName", @"name", @"species", @"lastName"] error:&error];
if (error) {
NSLog(@"Failed to create app: %@", error);
abort();
Expand Down
3 changes: 3 additions & 0 deletions Realm/ObjectServerTests/RLMUser+ObjectServerTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)waitForUploadToFinish:(NSString *)partitionValue;
- (BOOL)waitForDownloadToFinish:(NSString *)partitionValue;

- (BOOL)waitForUploadsForRealm:(RLMRealm *)realm error:(NSError **)error;
- (BOOL)waitForDownloadsForRealm:(RLMRealm *)realm error:(NSError **)error;

- (void)simulateClientResetErrorForSession:(NSString *)partitionValue;

@end
Expand Down
39 changes: 39 additions & 0 deletions Realm/ObjectServerTests/RLMUser+ObjectServerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,45 @@ - (BOOL)waitForDownloadToFinish:(NSString *)partitionValue {
return dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))) == 0;
}

- (BOOL)waitForUploadsForRealm:(RLMRealm *)realm error:(NSError **)error {
const NSTimeInterval timeout = 20;
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
RLMSyncSession *session = realm.syncSession;
NSAssert(session, @"Cannot call with invalid Realm");
__block NSError *completionError;
BOOL couldWait = [session waitForUploadCompletionOnQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0) callback:^(NSError *error) {
completionError = error;
dispatch_semaphore_signal(sema);
}];
if (!couldWait) {
return NO;
}

if (error)
*error = completionError;

return dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))) == 0;
}

- (BOOL)waitForDownloadsForRealm:(RLMRealm *)realm error:(NSError **)error {
const NSTimeInterval timeout = 20;
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
RLMSyncSession *session = realm.syncSession;
NSAssert(session, @"Cannot call with invalid Realm");
__block NSError *completionError;
BOOL couldWait = [session waitForDownloadCompletionOnQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0) callback:^(NSError *error) {
completionError = error;
}];
if (!couldWait) {
return NO;
}

if (error)
*error = completionError;

return dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))) == 0;
}

- (void)simulateClientResetErrorForSession:(NSString *)partitionValue {
RLMSyncSession *session = [self sessionForPartitionValue:partitionValue];
NSAssert(session, @"Cannot call with invalid URL");
Expand Down
2 changes: 1 addition & 1 deletion Realm/ObjectServerTests/RealmServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public class RealmServer: NSObject {
} else {
// This is a temporary workaround for not been able to add the complete schema for a flx App
syncTypes = schema.objectSchema.filter {
let validSyncClasses = ["Dog", "Person", "SwiftPerson", "SwiftTypesSyncObject"]
let validSyncClasses = ["Dog", "Person", "SwiftPerson", "SwiftDog", "Bird"]
return validSyncClasses.contains($0.className)
}
partitionKeyType = nil
Expand Down

0 comments on commit 2430945

Please sign in to comment.