diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index 4923299b83d..7ea9aa3f697 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -1231,25 +1231,29 @@ - (void)testResumingAQueryShouldUseBloomFilterToAvoidFullRequery { NSArray *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 *deletedDocumentIds; { + FIRFirestore* db2 = [self firestore]; + FIRWriteBatch* batch = [db2 batch]; + NSMutableArray *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");