Skip to content

Commit

Permalink
Use a different Firestore instance instead of a transaction or WriteB…
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe committed Jul 24, 2023
1 parent 5bcc4fe commit 15818b3
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Firestore/Example/Tests/Integration/API/FIRQueryTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1231,25 +1231,29 @@ - (void)testResumingAQueryShouldUseBloomFilterToAvoidFullRequery {
NSArray<FIRDocumentReference *> *createdDocuments =
FIRDocumentReferenceArrayFromQuerySnapshot(querySnapshot1);

// Delete 50 of the 100 documents. Do this in a transaction, rather than
// [FIRDocumentReference deleteDocument], to avoid affecting the local cache.
// Delete 50 of the 100 documents. Use a different Firestore instance to avoid affecting the
// local cache.
NSSet<NSString *> *deletedDocumentIds;
{
FIRFirestore* db2 = [self firestore];
FIRWriteBatch* batch = [db2 batch];

NSMutableArray<NSString *> *deletedDocumentIdsAccumulator = [[NSMutableArray alloc] init];
XCTestExpectation *expectation = [self expectationWithDescription:@"DeleteTransaction"];
[collRef.firestore
runTransactionWithBlock:^id _Nullable(FIRTransaction *transaction, NSError **) {
for (decltype(createdDocuments.count) i = 0; i < createdDocuments.count; i += 2) {
FIRDocumentReference *documentToDelete = createdDocuments[i];
[transaction deleteDocument:documentToDelete];
[deletedDocumentIdsAccumulator addObject:documentToDelete.documentID];
}
return @"document deletion successful";
}
completion:^(id, NSError *) {
[expectation fulfill];
}];
[self awaitExpectation:expectation];
for (decltype(createdDocuments.count) i = 0; i < createdDocuments.count; i += 2) {
FIRDocumentReference *documentToDelete = [db2 documentWithPath:createdDocuments[i].path];;
[batch deleteDocument:documentToDelete];
[deletedDocumentIdsAccumulator addObject:documentToDelete.documentID];
}

XCTestExpectation *commitExpectation = [self expectationWithDescription:@"WriteBatch commit"];
[batch commitWithCompletion:^(NSError *_Nullable error) {
[commitExpectation fulfill];
if (error != nil) {
XCTFail(@"WriteBatch commit failed: %@", error);
}
}];
[self awaitExpectation:commitExpectation];

deletedDocumentIds = [NSSet setWithArray:deletedDocumentIdsAccumulator];
}
XCTAssertEqual(deletedDocumentIds.count, 50u, @"deletedDocumentIds has the wrong size");
Expand Down

0 comments on commit 15818b3

Please sign in to comment.