diff --git a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm index 4923299b83d..9cfb6aabaf2 100644 --- a/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRQueryTests.mm @@ -1231,25 +1231,22 @@ - (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]; + } + + [self commitWriteBatch:batch]; + deletedDocumentIds = [NSSet setWithArray:deletedDocumentIdsAccumulator]; } XCTAssertEqual(deletedDocumentIds.count, 50u, @"deletedDocumentIds has the wrong size"); diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.h b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.h index c33f3f5bc97..eeed84ebf96 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.h +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.h @@ -115,6 +115,8 @@ extern "C" { data:(NSDictionary *)data fields:(NSArray *)fields; +- (void)commitWriteBatch:(FIRWriteBatch *)batch; + - (void)disableNetwork; - (void)enableNetwork; diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm index 07460c6ecf3..80c5ce42549 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm @@ -412,9 +412,7 @@ - (void)writeAllDocuments:(NSDictionary XCTestExpectation *commitExpectation = [self expectationWithDescription:@"WriteBatch commit"]; [writeBatch commitWithCompletion:^(NSError *_Nullable error) { [commitExpectation fulfill]; - if (error != nil) { - XCTFail(@"WriteBatch commit failed: %@", error); - } + XCTAssertNil(error, @"WriteBatch commit failed: %@", error); }]; [commits addObject:commitExpectation]; writeBatch = nil; @@ -426,9 +424,7 @@ - (void)writeAllDocuments:(NSDictionary XCTestExpectation *commitExpectation = [self expectationWithDescription:@"WriteBatch commit"]; [writeBatch commitWithCompletion:^(NSError *_Nullable error) { [commitExpectation fulfill]; - if (error != nil) { - XCTFail(@"WriteBatch commit failed: %@", error); - } + XCTAssertNil(error, @"WriteBatch commit failed: %@", error); }]; [commits addObject:commitExpectation]; } @@ -570,6 +566,15 @@ - (void)mergeDocumentRef:(FIRDocumentReference *)ref [self awaitExpectation:expectation]; } +- (void)commitWriteBatch:(FIRWriteBatch *)batch { + XCTestExpectation *expectation = [self expectationWithDescription:@"WriteBatch commit"]; + [batch commitWithCompletion:^(NSError *_Nullable error) { + [expectation fulfill]; + XCTAssertNil(error, @"WriteBatch commit should have succeeded, but it failed: %@", error); + }]; + [self awaitExpectation:expectation]; +} + - (void)disableNetwork { XCTestExpectation *expectation = [self expectationWithDescription:@"disableNetwork"]; [self.db disableNetworkWithCompletion:[self completionForExpectation:expectation]];