Skip to content

Commit 5bc4cc5

Browse files
Remove Held Write Acks (#2029)
* Drop acknowledged mutations in schema migration (#1818) Drop acknowledged mutations in schema migration as part of removing held write acks. Port of firebase/firebase-js-sdk#1149 * Change removeMutationBatch to remove a single batch (#1955) * Update Firestore Generated Protos * Adding UnknownDocument and hasCommittedMutations (#1971) * Removing held write batch handling from LocalStore (#1997) * View changes for held write acks (#2004) * Held Write Acks Unit Test Fixes (#2008) * Held Write Ack Removal Spec Tests (#2018) * Fix integration test
1 parent 6be1ddb commit 5bc4cc5

File tree

66 files changed

+66977
-37425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+66977
-37425
lines changed

Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ - (void)testEquals {
7373
}
7474

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

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

8282
FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[ doc1Old, doc2Old ]);
8383
FSTDocumentSet *newDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[ doc2New, doc2New ]);
@@ -93,7 +93,7 @@ - (void)testIncludeMetadataChanges {
9393
oldDocuments:oldDocuments
9494
documentChanges:documentChanges
9595
fromCache:NO
96-
hasPendingWrites:NO
96+
mutatedKeys:DocumentKeySet {}
9797
syncStateChanged:YES];
9898
FIRSnapshotMetadata *metadata =
9999
[FIRSnapshotMetadata snapshotMetadataWithPendingWrites:NO fromCache:NO];
@@ -105,11 +105,13 @@ - (void)testIncludeMetadataChanges {
105105
FIRQueryDocumentSnapshot *doc1Snap = [FIRQueryDocumentSnapshot snapshotWithFirestore:firestore
106106
documentKey:doc1New.key
107107
document:doc1New
108-
fromCache:NO];
108+
fromCache:NO
109+
hasPendingWrites:NO];
109110
FIRQueryDocumentSnapshot *doc2Snap = [FIRQueryDocumentSnapshot snapshotWithFirestore:firestore
110111
documentKey:doc2New.key
111112
document:doc2New
112-
fromCache:NO];
113+
fromCache:NO
114+
hasPendingWrites:NO];
113115

114116
NSArray<FIRDocumentChange *> *changesWithoutMetadata = @[
115117
[[FIRDocumentChange alloc] initWithType:FIRDocumentChangeTypeModified

Firestore/Example/Tests/API/FSTAPIHelpers.mm

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@
6363
NSDictionary<NSString *, id> *_Nullable data,
6464
BOOL hasMutations,
6565
BOOL fromCache) {
66-
FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil;
66+
FSTDocument *doc =
67+
data ? FSTTestDoc(path, version, data,
68+
hasMutations ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced)
69+
: nil;
6770
return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore()
6871
documentKey:testutil::Key(path)
6972
document:doc
70-
fromCache:fromCache];
73+
fromCache:fromCache
74+
hasPendingWrites:hasMutations];
7175
}
7276

7377
FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path) {
@@ -90,28 +94,40 @@
9094
FIRSnapshotMetadata *metadata =
9195
[FIRSnapshotMetadata snapshotMetadataWithPendingWrites:hasPendingWrites fromCache:fromCache];
9296
FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]);
97+
DocumentKeySet mutatedKeys;
9398
for (NSString *key in oldDocs) {
94-
oldDocuments =
95-
[oldDocuments documentSetByAddingDocument:FSTTestDoc(util::StringFormat("%s/%s", path, key),
96-
1, oldDocs[key], hasPendingWrites)];
99+
oldDocuments = [oldDocuments
100+
documentSetByAddingDocument:FSTTestDoc(util::StringFormat("%s/%s", path, key), 1,
101+
oldDocs[key],
102+
hasPendingWrites ? FSTDocumentStateLocalMutations
103+
: FSTDocumentStateSynced)];
104+
if (hasPendingWrites) {
105+
const absl::string_view documentKey = util::StringFormat("%s/%s", path, key);
106+
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
107+
}
97108
}
98109
FSTDocumentSet *newDocuments = oldDocuments;
99110
NSArray<FSTDocumentViewChange *> *documentChanges = [NSArray array];
100111
for (NSString *key in docsToAdd) {
101112
FSTDocument *docToAdd =
102-
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, docsToAdd[key], hasPendingWrites);
113+
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, docsToAdd[key],
114+
hasPendingWrites ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced);
103115
newDocuments = [newDocuments documentSetByAddingDocument:docToAdd];
104116
documentChanges = [documentChanges
105117
arrayByAddingObject:[FSTDocumentViewChange
106118
changeWithDocument:docToAdd
107119
type:FSTDocumentViewChangeTypeAdded]];
120+
if (hasPendingWrites) {
121+
const absl::string_view documentKey = util::StringFormat("%s/%s", path, key);
122+
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
123+
}
108124
}
109125
FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path)
110126
documents:newDocuments
111127
oldDocuments:oldDocuments
112128
documentChanges:documentChanges
113129
fromCache:fromCache
114-
hasPendingWrites:hasPendingWrites
130+
mutatedKeys:mutatedKeys
115131
syncStateChanged:YES];
116132
return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore()
117133
originalQuery:FSTTestQuery(path)

Firestore/Example/Tests/Core/FSTQueryListenerTests.mm

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ - (void)testRaisesCollectionEvents {
5656
NSMutableArray<FSTViewSnapshot *> *otherAccum = [NSMutableArray array];
5757

5858
FSTQuery *query = FSTTestQuery("rooms");
59-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
60-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
61-
FSTDocument *doc2prime =
62-
FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO);
59+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
60+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
61+
FSTDocument *doc2prime = FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"},
62+
FSTDocumentStateSynced);
6363

6464
FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum];
6565
FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum];
@@ -91,7 +91,7 @@ - (void)testRaisesCollectionEvents {
9191
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap2.query.comparator]
9292
documentChanges:@[ change1, change4 ]
9393
fromCache:snap2.fromCache
94-
hasPendingWrites:snap2.hasPendingWrites
94+
mutatedKeys:snap2.mutatedKeys
9595
syncStateChanged:YES];
9696
XCTAssertEqualObjects(otherAccum, (@[ expectedSnap2 ]));
9797
}
@@ -133,8 +133,8 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
133133
NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array];
134134

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

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

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

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

209209
FSTQuery *query = FSTTestQuery("rooms");
210-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
211-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
212-
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
213-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
210+
FSTDocument *doc1 =
211+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
212+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
213+
FSTDocument *doc1Prime =
214+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
215+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
214216

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

258260
FSTQuery *query = FSTTestQuery("rooms");
259-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
260-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, YES);
261-
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
262-
FSTDocument *doc2Prime = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
263-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
261+
FSTDocument *doc1 =
262+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
263+
FSTDocument *doc2 =
264+
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateLocalMutations);
265+
FSTDocument *doc1Prime =
266+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
267+
FSTDocument *doc2Prime =
268+
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
269+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
264270

265271
FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
266272
includeDocumentMetadataChanges:NO
@@ -284,7 +290,7 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
284290
oldDocuments:snap3.documents
285291
documentChanges:@[]
286292
fromCache:snap4.fromCache
287-
hasPendingWrites:NO
293+
mutatedKeys:snap4.mutatedKeys
288294
syncStateChanged:snap4.syncStateChanged];
289295
XCTAssertEqualObjects(fullAccum, (@[ snap1, snap3, expectedSnap4 ]));
290296
}
@@ -293,10 +299,12 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
293299
NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array];
294300

295301
FSTQuery *query = FSTTestQuery("rooms");
296-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
297-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
298-
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
299-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
302+
FSTDocument *doc1 =
303+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
304+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
305+
FSTDocument *doc1Prime =
306+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
307+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
300308

301309
FSTQueryListener *filteredListener =
302310
[self listenToQuery:query accumulatingSnapshots:filteredAccum];
@@ -316,7 +324,7 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
316324
oldDocuments:snap1.documents
317325
documentChanges:@[ change3 ]
318326
fromCache:snap2.isFromCache
319-
hasPendingWrites:snap2.hasPendingWrites
327+
mutatedKeys:snap2.mutatedKeys
320328
syncStateChanged:snap2.syncStateChanged];
321329
XCTAssertEqualObjects(filteredAccum, (@[ snap1, expectedSnap2 ]));
322330
}
@@ -325,8 +333,8 @@ - (void)testWillWaitForSyncIfOnline {
325333
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];
326334

327335
FSTQuery *query = FSTTestQuery("rooms");
328-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
329-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
336+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
337+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
330338
FSTQueryListener *listener =
331339
[self listenToQuery:query
332340
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
@@ -357,7 +365,7 @@ - (void)testWillWaitForSyncIfOnline {
357365
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap3.query.comparator]
358366
documentChanges:@[ change1, change2 ]
359367
fromCache:NO
360-
hasPendingWrites:NO
368+
mutatedKeys:snap3.mutatedKeys
361369
syncStateChanged:YES];
362370
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
363371
}
@@ -366,8 +374,8 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
366374
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];
367375

368376
FSTQuery *query = FSTTestQuery("rooms");
369-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
370-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
377+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
378+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
371379
FSTQueryListener *listener =
372380
[self listenToQuery:query
373381
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
@@ -396,14 +404,14 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
396404
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
397405
documentChanges:@[ change1 ]
398406
fromCache:YES
399-
hasPendingWrites:NO
407+
mutatedKeys:snap1.mutatedKeys
400408
syncStateChanged:YES];
401409
FSTViewSnapshot *expectedSnap2 = [[FSTViewSnapshot alloc] initWithQuery:query
402410
documents:snap2.documents
403411
oldDocuments:snap1.documents
404412
documentChanges:@[ change2 ]
405413
fromCache:YES
406-
hasPendingWrites:NO
414+
mutatedKeys:snap2.mutatedKeys
407415
syncStateChanged:NO];
408416
XCTAssertEqualObjects(events, (@[ expectedSnap1, expectedSnap2 ]));
409417
}
@@ -429,7 +437,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
429437
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
430438
documentChanges:@[]
431439
fromCache:YES
432-
hasPendingWrites:NO
440+
mutatedKeys:snap1.mutatedKeys
433441
syncStateChanged:YES];
434442
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
435443
}
@@ -454,7 +462,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
454462
oldDocuments:[FSTDocumentSet documentSetWithComparator:snap1.query.comparator]
455463
documentChanges:@[]
456464
fromCache:YES
457-
hasPendingWrites:NO
465+
mutatedKeys:snap1.mutatedKeys
458466
syncStateChanged:YES];
459467
XCTAssertEqualObjects(events, (@[ expectedSnap ]));
460468
}

0 commit comments

Comments
 (0)