Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaafanador3 committed Jul 29, 2022
1 parent 65f5c81 commit 65bd7eb
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 423 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ disabled_rules:
# #unavailable was implemented in Swift 5.6 so we can't use it until that's
# the minimum version we support
- unavailable_condition
- large_tuple
3 changes: 0 additions & 3 deletions Realm/ObjectServerTests/RLMUser+ObjectServerTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ 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: 0 additions & 39 deletions Realm/ObjectServerTests/RLMUser+ObjectServerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,6 @@ - (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
4 changes: 3 additions & 1 deletion Realm/ObjectServerTests/SwiftFlexibleSyncServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,10 @@ extension SwiftFlexibleSyncTests {
XCTAssertEqual(realm.subscriptions.count, numberOfSubs)

var count = 0
for subscription in realm.subscriptions {
for (index, subscription) in realm.subscriptions.enumerated() {
XCTAssertNotNil(subscription)
XCTAssertEqual(subscription.query, "age > \(index + 1)")
XCTAssertTrue((Calendar.current.date(byAdding: DateComponents(hour: -1), to: Date())!...Date()).contains(subscription.createdAt))
count += 1
}

Expand Down
1 change: 1 addition & 0 deletions Realm/ObjectServerTests/SwiftObjectServerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,7 @@ class CombineObjectServerTests: SwiftSyncTestCase {
}

#if swift(>=5.6) && canImport(_Concurrency)

@available(macOS 12.0, *)
class AsyncAwaitObjectServerTests: SwiftSyncTestCase {
override class var defaultTestSuite: XCTestSuite {
Expand Down
12 changes: 11 additions & 1 deletion Realm/RLMSyncSubscription.mm
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ NSUInteger RLMFastEnumerate(NSFastEnumerationState *state,

@implementation RLMSyncSubscriptionSet {
std::mutex _collectionEnumeratorMutex;
RLMRealm *_realm;
}

- (instancetype)initWithSubscriptionSet:(realm::sync::SubscriptionSet)subscriptionSet
Expand Down Expand Up @@ -245,6 +244,12 @@ - (void)update:(__attribute__((noescape)) void(^)(void))block {
}

- (void)update:(__attribute__((noescape)) void(^)(void))block onComplete:(void(^)(NSError *))completionBlock {
return [self update:block queue:nil onComplete:completionBlock];
}

- (void)update:(__attribute__((noescape)) void(^)(void))block
queue:(nullable dispatch_queue_t)queue
onComplete:(void(^)(NSError *))completionBlock {
if (_mutableSubscriptionSet != nil) {
@throw RLMException(@"Cannot initiate a write transaction on subscription set that is already been updated.");
}
Expand Down Expand Up @@ -285,6 +290,11 @@ - (void)waitForSynchronizationOnQueue:(nullable dispatch_queue_t)queue
});
}

- (void)write:(__attribute__((noescape)) void(^)(void))block onComplete:(void(^)(NSError *))completionBlock {
[self update:block queue:nil onComplete:completionBlock];
}


#pragma mark - Find subscription

- (nullable RLMSyncSubscription *)subscriptionWithName:(NSString *)name {
Expand Down
3 changes: 3 additions & 0 deletions Realm/RLMSyncSubscription_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ NS_ASSUME_NONNULL_BEGIN

@interface RLMSyncSubscriptionSet ()

@property (nonatomic, readonly) RLMRealm *realm;
@property (readonly) uint64_t version;

- (void)update:(__attribute__((noescape)) void(^)(void))block queue:(nullable dispatch_queue_t)queue onComplete:(void(^)(NSError *))completionBlock;

- (void)addSubscriptionWithClassName:(NSString *)objectClassName
subscriptionName:(nullable NSString *)name
predicate:(NSPredicate *)predicate
Expand Down

0 comments on commit 65bd7eb

Please sign in to comment.