Browse Source

Fix scary type errors and add tests.

Some compiler warnings caught cases where an FSyncTree was passed
into an id<FNode> method. Added test cases for online behavior,
but I can't test this until it hits travis because the online changes
aren't live and I don't know how to manually target the emulator in
this SDK.
Thomas Bouldin 6 years ago
parent
commit
1b4912d08c

+ 32 - 5
Example/Database/Tests/Integration/FData.m

@@ -2874,7 +2874,15 @@
                 @"Number should be no more than 2 seconds ago");
 }
 
-- (void)testServerIncrementOverwritesExistingData {
+- (void)testServerIncrementOverwritesExistingDataOnline {
+  [self checkServerIncrementOverwritesExistingDataWhileOnline:true];
+}
+
+- (void)testServerIncrementOverwritesExistingDataOffline {
+  [self checkServerIncrementOverwritesExistingDataWhileOnline:false];
+}
+
+- (void)checkServerIncrementOverwritesExistingDataWhileOnline:(BOOL)online {
   FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
   __block NSMutableArray *found = [NSMutableArray new];
   NSMutableArray *expected = [NSMutableArray new];
@@ -2884,7 +2892,9 @@
               }];
 
   // Going offline ensures that local events get queued up before server events
-  [ref.repo interrupt];
+  if (!online) {
+    [ref.repo interrupt];
+  }
 
   // null + incr
   [ref setValue:[FIRServerValue increment:@1]];
@@ -2912,11 +2922,25 @@
     return found.count == expected.count;
   }];
   XCTAssertEqualObjects(expected, found);
-  [ref.repo resume];
+  
+  if (!online) {
+    [ref.repo resume];
+  }
 }
 
-- (void)testServerIncrementPriority {
+- (void)testServerIncrementPriorityOnline {
+  [self checkServerIncrementPriorityWhileOnline:true];
+}
+
+- (void)testServerIncrementPriorityOffline {
+  [self checkServerIncrementPriorityWhileOnline:false];
+}
+
+- (void)checkServerIncrementPriorityWhileOnline:(BOOL)online {
   FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
+  if (!online) {
+    [ref.repo interrupt];
+  }
   __block NSMutableArray *found = [NSMutableArray new];
   NSMutableArray *expected = [NSMutableArray new];
   [ref observeEventType:FIRDataEventTypeValue
@@ -2938,7 +2962,10 @@
     return found.count == expected.count;
   }];
   XCTAssertEqualObjects(expected, found);
-  [ref.repo resume];
+  
+  if (!online) {
+    [ref.repo resume];
+  }
 }
 
 - (void)testServerIncrementOverflowAndTypeCoercion {

+ 1 - 1
Firebase/Database/Core/FRepo.m

@@ -248,7 +248,7 @@
                       withCallback:callback];
           id<FNode> resolved =
               [FServerValues resolveDeferredValueSnapshot:write.overwrite
-                                             withExisting:self.serverSyncTree
+                                             withSyncTree:self.serverSyncTree
                                                    atPath:write.path
                                              serverValues:serverValues];
           [self.serverSyncTree applyUserOverwriteAtPath:write.path

+ 1 - 1
Firebase/Database/Core/FSyncTree.m

@@ -234,7 +234,7 @@ static const NSUInteger kFSizeThresholdForCompoundHash = 1024;
             if ([write isOverwrite]) {
                 id<FNode> resolvedNode =
                     [FServerValues resolveDeferredValueSnapshot:write.overwrite
-                                                   withExisting:self
+                                                   withSyncTree:self
                                                          atPath:write.path
                                                    serverValues:serverValues];
                 [self.persistenceManager applyUserWrite:resolvedNode