Skip to content

Commit c27b3c9

Browse files
committed
more work on the implementation
1 parent 27ade69 commit c27b3c9

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

Firestore/Example/Tests/Integration/API/FIRQueryTests.mm

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ - (void)testUseInWithArrayContains {
11531153
[self checkOnlineAndOfflineQuery:[collRef queryWhereFilter:filter4] matchesResult:@[ @"doc3" ]];
11541154
}
11551155

1156+
11561157
- (void)testOrderByEquality {
11571158
// TODO(orquery): Enable this test against production when possible.
11581159
XCTSkipIf(![FSTIntegrationTestCase isRunningAgainstEmulator],
@@ -1180,7 +1181,7 @@ - (void)testOrderByEquality {
11801181
matchesResult:@[ @"doc6", @"doc3" ]];
11811182
}
11821183

1183-
- (void)resumingAQueryShouldUseExistenceFilterToDetectDeletes {
1184+
- (void)testResumingAQueryShouldUseExistenceFilterToDetectDeletes {
11841185
// Prepare the names and contents of the 100 documents to create.
11851186
NSMutableDictionary<NSString*, NSDictionary<NSString *, id>*>* testData = [[NSMutableDictionary alloc] init];
11861187
for (int i=0; i<100; i++) {
@@ -1193,15 +1194,53 @@ - (void)resumingAQueryShouldUseExistenceFilterToDetectDeletes {
11931194
// Run a query to populate the local cache with the 100 documents and a resume token.
11941195
NSArray<FIRDocumentReference*>* createdDocuments;
11951196
{
1196-
FIRQuerySnapshot *querySnapshot = [self readDocumentSetForRef:collRef source:FIRFirestoreSourceDefault];
1197+
FIRQuerySnapshot *querySnapshot1 = [self readDocumentSetForRef:collRef source:FIRFirestoreSourceDefault];
11971198
NSMutableArray<FIRDocumentReference*>* createdDocumentsAccumulator = [[NSMutableArray alloc] init];
1198-
for (FIRDocumentSnapshot* documentSnapshot in querySnapshot.documents) {
1199+
for (FIRDocumentSnapshot* documentSnapshot in querySnapshot1.documents) {
11991200
[createdDocumentsAccumulator addObject:documentSnapshot.reference];
12001201
}
12011202
createdDocuments = [createdDocumentsAccumulator copy];
12021203
}
12031204

1204-
(void)createdDocuments;
1205+
// Delete 50 of the 100 documents. Do this in a transaction, rather than
1206+
// [FIRDocumentReference deleteDocument], to avoid affecting the local cache.
1207+
NSSet<NSString*>* deletedDocumentIds;
1208+
{
1209+
NSMutableSet<NSString*>* deletedDocumentIdsAccumulator = [[NSMutableSet alloc] init];
1210+
deletedDocumentIds = [deletedDocumentIdsAccumulator copy];
1211+
XCTestExpectation *expectation = [self expectationWithDescription:@"DeleteTransaction"];
1212+
[collRef.firestore runTransactionWithBlock:
1213+
^id _Nullable(FIRTransaction* transaction, NSError** error) {
1214+
for (NSUInteger i=0; i<createdDocuments.count; i+=2) {
1215+
FIRDocumentReference* documentToDelete = createdDocuments[i];
1216+
[transaction deleteDocument:documentToDelete];
1217+
[deletedDocumentIdsAccumulator addObject:documentToDelete.documentID];
1218+
}
1219+
return @"document deletion successful";
1220+
}
1221+
completion:
1222+
^(id, NSError *){
1223+
[expectation fulfill];
1224+
}
1225+
];
1226+
[self awaitExpectation:expectation];
1227+
}
1228+
1229+
// Wait for 10 seconds, during which Watch will stop tracking the query and will send an existence
1230+
// filter rather than "delete" events when the query is resumed.
1231+
[NSThread sleepForTimeInterval:10.0f];
1232+
1233+
// Resume the query and save the resulting snapshot for verification.
1234+
FIRQuerySnapshot *querySnapshot2 = [self readDocumentSetForRef:collRef source:FIRFirestoreSourceDefault];
1235+
1236+
// Verify that the snapshot from the resumed query contains the expected documents; that is,
1237+
// that it contains the 50 documents that were _not_ deleted.
1238+
// TODO(b/270731363): Remove the "if" condition below once the Firestore Emulator is fixed to
1239+
// send an existence filter. At the time of writing, the Firestore emulator fails to send an
1240+
// existence filter, resulting in the client including the deleted documents in the snapshot
1241+
// of the resumed query.
1242+
if (!([FSTIntegrationTestCase isRunningAgainstEmulator] && querySnapshot2.count == 100)) {
1243+
}
12051244
}
12061245

12071246
@end

0 commit comments

Comments
 (0)