Skip to content

Remove Held Write Acks #2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ - (void)testEquals {
}

- (void)testIncludeMetadataChanges {
FSTDocument *doc1Old = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, YES);
FSTDocument *doc1New = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, NO);
FSTDocument *doc1Old = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, FSTDocumentStateLocalMutations);
FSTDocument *doc1New = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, FSTDocumentStateSynced);

FSTDocument *doc2Old = FSTTestDoc("foo/baz", 1, @{@"a" : @"b"}, NO);
FSTDocument *doc2New = FSTTestDoc("foo/baz", 1, @{@"a" : @"c"}, NO);
FSTDocument *doc2Old = FSTTestDoc("foo/baz", 1, @{@"a" : @"b"}, FSTDocumentStateSynced);
FSTDocument *doc2New = FSTTestDoc("foo/baz", 1, @{@"a" : @"c"}, FSTDocumentStateSynced);

FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[ doc1Old, doc2Old ]);
FSTDocumentSet *newDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[ doc2New, doc2New ]);
Expand All @@ -93,7 +93,7 @@ - (void)testIncludeMetadataChanges {
oldDocuments:oldDocuments
documentChanges:documentChanges
fromCache:NO
hasPendingWrites:NO
mutatedKeys:DocumentKeySet {}
syncStateChanged:YES];
FIRSnapshotMetadata *metadata =
[FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO];
Expand All @@ -105,11 +105,13 @@ - (void)testIncludeMetadataChanges {
FIRQueryDocumentSnapshot *doc1Snap = [FIRQueryDocumentSnapshot snapshotWithFirestore:firestore
documentKey:doc1New.key
document:doc1New
fromCache:NO];
fromCache:NO
hasPendingWrites:NO];
FIRQueryDocumentSnapshot *doc2Snap = [FIRQueryDocumentSnapshot snapshotWithFirestore:firestore
documentKey:doc2New.key
document:doc2New
fromCache:NO];
fromCache:NO
hasPendingWrites:NO];

NSArray<FIRDocumentChange *> *changesWithoutMetadata = @[
[[FIRDocumentChange alloc] initWithType:FIRDocumentChangeTypeModified
Expand Down
30 changes: 23 additions & 7 deletions Firestore/Example/Tests/API/FSTAPIHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
BOOL fromCache) {
FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil;
FSTDocument *doc =
data ? FSTTestDoc(path, version, data,
hasMutations ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced)
: nil;
return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore()
documentKey:testutil::Key(path)
document:doc
fromCache:fromCache];
fromCache:fromCache
hasPendingWrites:hasMutations];
}

FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path) {
Expand All @@ -90,28 +94,40 @@
FIRSnapshotMetadata *metadata =
[FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites fromCache:fromCache];
FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]);
DocumentKeySet mutatedKeys;
for (NSString *key in oldDocs) {
oldDocuments =
[oldDocuments documentSetByAddingDocument:FSTTestDoc(util::StringFormat("%s/%s", path, key),
1, oldDocs[key], hasPendingWrites)];
oldDocuments = [oldDocuments
documentSetByAddingDocument:FSTTestDoc(util::StringFormat("%s/%s", path, key), 1,
oldDocs[key],
hasPendingWrites ? FSTDocumentStateLocalMutations
: FSTDocumentStateSynced)];
if (hasPendingWrites) {
const absl::string_view documentKey = util::StringFormat("%s/%s", path, key);
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
}
}
FSTDocumentSet *newDocuments = oldDocuments;
NSArray<FSTDocumentViewChange *> *documentChanges = [NSArray array];
for (NSString *key in docsToAdd) {
FSTDocument *docToAdd =
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, docsToAdd[key], hasPendingWrites);
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, docsToAdd[key],
hasPendingWrites ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced);
newDocuments = [newDocuments documentSetByAddingDocument:docToAdd];
documentChanges = [documentChanges
arrayByAddingObject:[FSTDocumentViewChange
changeWithDocument:docToAdd
type:FSTDocumentViewChangeTypeAdded]];
if (hasPendingWrites) {
const absl::string_view documentKey = util::StringFormat("%s/%s", path, key);
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
}
}
FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path)
documents:newDocuments
oldDocuments:oldDocuments
documentChanges:documentChanges
fromCache:fromCache
hasPendingWrites:hasPendingWrites
mutatedKeys:mutatedKeys
syncStateChanged:YES];
return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore()
originalQuery:FSTTestQuery(path)
Expand Down
74 changes: 41 additions & 33 deletions Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ - (void)testRaisesCollectionEvents {
NSMutableArray<FSTViewSnapshot *> *otherAccum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc2prime =
FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO);
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTDocument *doc2prime = FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"},
FSTDocumentStateSynced);

FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum];
FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum];
Expand Down Expand Up @@ -91,7 +91,7 @@ - (void)testRaisesCollectionEvents {
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap2.query.comparator]
documentChanges:@[ change1, change4 ]
fromCache:snap2.fromCache
hasPendingWrites:snap2.hasPendingWrites
mutatedKeys:snap2.mutatedKeys
syncStateChanged:YES];
XCTAssertEqualObjects(otherAccum, (@[ expectedSnap2 ]));
}
Expand Down Expand Up @@ -133,8 +133,8 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms/Eros");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, NO);
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, FSTDocumentStateSynced);

__block FSTAsyncQueryListener *listener =
[[FSTAsyncQueryListener alloc] initWithExecutor:_executor.get()
Expand Down Expand Up @@ -171,8 +171,8 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);

FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
includeDocumentMetadataChanges:NO
Expand Down Expand Up @@ -207,10 +207,12 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
FSTDocument *doc1 =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTDocument *doc1Prime =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);

FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
includeDocumentMetadataChanges:YES
Expand Down Expand Up @@ -256,11 +258,15 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, YES);
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2Prime = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
FSTDocument *doc1 =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
FSTDocument *doc2 =
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateLocalMutations);
FSTDocument *doc1Prime =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2Prime =
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);

FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
includeDocumentMetadataChanges:NO
Expand All @@ -284,7 +290,7 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
oldDocuments:snap3.documents
documentChanges:@[]
fromCache:snap4.fromCache
hasPendingWrites:NO
mutatedKeys:snap4.mutatedKeys
syncStateChanged:snap4.syncStateChanged];
XCTAssertEqualObjects(fullAccum, (@[ snap1, snap3, expectedSnap4 ]));
}
Expand All @@ -293,10 +299,12 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
FSTDocument *doc1 =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTDocument *doc1Prime =
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);

FSTQueryListener *filteredListener =
[self listenToQuery:query accumulatingSnapshots:filteredAccum];
Expand All @@ -316,7 +324,7 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
oldDocuments:snap1.documents
documentChanges:@[ change3 ]
fromCache:snap2.isFromCache
hasPendingWrites:snap2.hasPendingWrites
mutatedKeys:snap2.mutatedKeys
syncStateChanged:snap2.syncStateChanged];
XCTAssertEqualObjects(filteredAccum, (@[ snap1, expectedSnap2 ]));
}
Expand All @@ -325,8 +333,8 @@ - (void)testWillWaitForSyncIfOnline {
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTQueryListener *listener =
[self listenToQuery:query
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
Expand Down Expand Up @@ -357,7 +365,7 @@ - (void)testWillWaitForSyncIfOnline {
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap3.query.comparator]
documentChanges:@[ change1, change2 ]
fromCache:NO
hasPendingWrites:NO
mutatedKeys:snap3.mutatedKeys
syncStateChanged:YES];
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
}
Expand All @@ -366,8 +374,8 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];

FSTQuery *query = FSTTestQuery("rooms");
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
FSTQueryListener *listener =
[self listenToQuery:query
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
Expand Down Expand Up @@ -396,14 +404,14 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
documentChanges:@[ change1 ]
fromCache:YES
hasPendingWrites:NO
mutatedKeys:snap1.mutatedKeys
syncStateChanged:YES];
FSTViewSnapshot *expectedSnap2 = [[FSTViewSnapshot alloc] initWithQuery:query
documents:snap2.documents
oldDocuments:snap1.documents
documentChanges:@[ change2 ]
fromCache:YES
hasPendingWrites:NO
mutatedKeys:snap2.mutatedKeys
syncStateChanged:NO];
XCTAssertEqualObjects(events, (@[ expectedSnap1, expectedSnap2 ]));
}
Expand All @@ -429,7 +437,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
documentChanges:@[]
fromCache:YES
hasPendingWrites:NO
mutatedKeys:snap1.mutatedKeys
syncStateChanged:YES];
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
}
Expand All @@ -454,7 +462,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
documentChanges:@[]
fromCache:YES
hasPendingWrites:NO
mutatedKeys:snap1.mutatedKeys
syncStateChanged:YES];
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
}
Expand Down
Loading