diff options
author | Greg Soltis <gsoltis@google.com> | 2018-04-25 13:45:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 13:45:21 -0700 |
commit | 0748f265a6c95e2692f27ad59235521cb45e175d (patch) | |
tree | 572f957f0b43de69ab41f94dceeda18cdfc88605 /Firestore/Example | |
parent | ff32b59036f35512c64fcd75ae5cee8aca228929 (diff) |
Identify limbo-only document updates (#1167)
* Filter out document updates from target association changes
* Move remote-event-modifying methods onto remote event
* Style
* keep limbo docs in remote event
* Implement identification of limbo document updates
* Refactor a bit to handle removes as well
* Drop newline
* Handle synthesized limbo deletes
* Response to feedback
* Appease the style gods
Diffstat (limited to 'Firestore/Example')
-rw-r--r-- | Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm index 6ac2a6b..35903e7 100644 --- a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm +++ b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm @@ -18,6 +18,7 @@ #import <XCTest/XCTest.h> +#import "Firestore/Source/Core/FSTQuery.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentKey.h" @@ -581,14 +582,17 @@ NS_ASSUME_NONNULL_BEGIN FSTDeletedDocument *expected = [FSTDeletedDocument documentWithKey:synthesized version:event.snapshotVersion]; XCTAssertEqualObjects(expected, event.documentUpdates.at(synthesized)); + XCTAssertTrue([event.limboDocumentChanges containsObject:synthesized]); - DocumentKey notSynthesized1 = DocumentKey::FromPathString("docs/no1"); - [event synthesizeDeleteForLimboTargetChange:event.targetChanges[@2] key:notSynthesized1]; - XCTAssertEqual(event.documentUpdates.find(notSynthesized1), event.documentUpdates.end()); + DocumentKey notSynthesized = DocumentKey::FromPathString("docs/no1"); + [event synthesizeDeleteForLimboTargetChange:event.targetChanges[@2] key:notSynthesized]; + XCTAssertEqual(event.documentUpdates.find(notSynthesized), event.documentUpdates.end()); + XCTAssertFalse([event.limboDocumentChanges containsObject:notSynthesized]); [event synthesizeDeleteForLimboTargetChange:event.targetChanges[@3] key:doc.key]; FSTMaybeDocument *docData = event.documentUpdates.at(doc.key); XCTAssertFalse([docData isKindOfClass:[FSTDeletedDocument class]]); + XCTAssertFalse([event.limboDocumentChanges containsObject:doc.key]); } - (void)testFilterUpdates { @@ -639,6 +643,55 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertTrue([resetMapping.documents containsObject:existingDocKey]); } +- (void)testTracksLimboDocuments { + // Add 3 docs: 1 is limbo and non-limbo, 2 is limbo-only, 3 is non-limbo + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{@"key" : @"value"}, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 1, @{@"key" : @"value"}, NO); + FSTDocument *doc3 = FSTTestDoc("docs/3", 1, @{@"key" : @"value"}, NO); + + // Target 2 is a limbo target + + FSTWatchChange *docChange1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1, @2 ] + removedTargetIDs:@[] + documentKey:doc1.key + document:doc1]; + + FSTWatchChange *docChange2 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @2 ] + removedTargetIDs:@[] + documentKey:doc2.key + document:doc2]; + + FSTWatchChange *docChange3 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] + removedTargetIDs:@[] + documentKey:doc3.key + document:doc3]; + + FSTWatchChange *targetsChange = + [FSTWatchTargetChange changeWithState:FSTWatchTargetChangeStateCurrent targetIDs:@[ @1, @2 ]]; + + NSMutableDictionary<NSNumber *, FSTQueryData *> *listens = [NSMutableDictionary dictionary]; + listens[@1] = [FSTQueryData alloc]; + listens[@2] = [[FSTQueryData alloc] initWithQuery:[FSTQuery alloc] + targetID:2 + listenSequenceNumber:1000 + purpose:FSTQueryPurposeLimboResolution]; + FSTWatchChangeAggregator *aggregator = + [[FSTWatchChangeAggregator alloc] initWithSnapshotVersion:FSTTestVersion(3) + listenTargets:listens + pendingTargetResponses:@{}]; + + [aggregator addWatchChanges:@[ docChange1, docChange2, docChange3, targetsChange ]]; + + FSTRemoteEvent *event = [aggregator remoteEvent]; + FSTDocumentKeySet *limboDocChanges = event.limboDocumentChanges; + // Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo + XCTAssertFalse([limboDocChanges containsObject:doc1.key]); + // Doc2 is only in the limbo target, so is tracked as a limbo document + XCTAssertTrue([limboDocChanges containsObject:doc2.key]); + // Doc3 is only in the non-limbo target, therefore not tracked as limbo + XCTAssertFalse([limboDocChanges containsObject:doc3.key]); +} + @end NS_ASSUME_NONNULL_END |