Skip to content

Commit 15818b3

Browse files
committed
Use a different Firestore instance instead of a transaction or WriteBatch (ports firebase/firebase-js-sdk#7415 and firebase/firebase-js-sdk#7486)
1 parent 5bcc4fe commit 15818b3

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -1231,25 +1231,29 @@ - (void)testResumingAQueryShouldUseBloomFilterToAvoidFullRequery {
12311231
NSArray<FIRDocumentReference *> *createdDocuments =
12321232
FIRDocumentReferenceArrayFromQuerySnapshot(querySnapshot1);
12331233

1234-
// Delete 50 of the 100 documents. Do this in a transaction, rather than
1235-
// [FIRDocumentReference deleteDocument], to avoid affecting the local cache.
1234+
// Delete 50 of the 100 documents. Use a different Firestore instance to avoid affecting the
1235+
// local cache.
12361236
NSSet<NSString *> *deletedDocumentIds;
12371237
{
1238+
FIRFirestore* db2 = [self firestore];
1239+
FIRWriteBatch* batch = [db2 batch];
1240+
12381241
NSMutableArray<NSString *> *deletedDocumentIdsAccumulator = [[NSMutableArray alloc] init];
1239-
XCTestExpectation *expectation = [self expectationWithDescription:@"DeleteTransaction"];
1240-
[collRef.firestore
1241-
runTransactionWithBlock:^id _Nullable(FIRTransaction *transaction, NSError **) {
1242-
for (decltype(createdDocuments.count) i = 0; i < createdDocuments.count; i += 2) {
1243-
FIRDocumentReference *documentToDelete = createdDocuments[i];
1244-
[transaction deleteDocument:documentToDelete];
1245-
[deletedDocumentIdsAccumulator addObject:documentToDelete.documentID];
1246-
}
1247-
return @"document deletion successful";
1248-
}
1249-
completion:^(id, NSError *) {
1250-
[expectation fulfill];
1251-
}];
1252-
[self awaitExpectation:expectation];
1242+
for (decltype(createdDocuments.count) i = 0; i < createdDocuments.count; i += 2) {
1243+
FIRDocumentReference *documentToDelete = [db2 documentWithPath:createdDocuments[i].path];;
1244+
[batch deleteDocument:documentToDelete];
1245+
[deletedDocumentIdsAccumulator addObject:documentToDelete.documentID];
1246+
}
1247+
1248+
XCTestExpectation *commitExpectation = [self expectationWithDescription:@"WriteBatch commit"];
1249+
[batch commitWithCompletion:^(NSError *_Nullable error) {
1250+
[commitExpectation fulfill];
1251+
if (error != nil) {
1252+
XCTFail(@"WriteBatch commit failed: %@", error);
1253+
}
1254+
}];
1255+
[self awaitExpectation:commitExpectation];
1256+
12531257
deletedDocumentIds = [NSSet setWithArray:deletedDocumentIdsAccumulator];
12541258
}
12551259
XCTAssertEqual(deletedDocumentIds.count, 50u, @"deletedDocumentIds has the wrong size");

0 commit comments

Comments
 (0)