aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Util/FSTIntegrationTestCase.m
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Example/Tests/Util/FSTIntegrationTestCase.m')
-rw-r--r--Firestore/Example/Tests/Util/FSTIntegrationTestCase.m36
1 files changed, 35 insertions, 1 deletions
diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.m b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.m
index 87a78c3..2e1e0a9 100644
--- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.m
+++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.m
@@ -30,9 +30,14 @@
#import "Util/FSTUtil.h"
#import "FSTEventAccumulator.h"
+#import "FSTTestDispatchQueue.h"
NS_ASSUME_NONNULL_BEGIN
+@interface FIRFirestore (Testing)
+@property(nonatomic, strong) FSTDispatchQueue *workerDispatchQueue;
+@end
+
@implementation FSTIntegrationTestCase {
NSMutableArray<FIRFirestore *> *_firestores;
}
@@ -121,7 +126,7 @@ NS_ASSUME_NONNULL_BEGIN
- (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
NSString *persistenceKey = [NSString stringWithFormat:@"db%lu", (unsigned long)_firestores.count];
- FSTDispatchQueue *workerDispatchQueue = [FSTDispatchQueue
+ FSTTestDispatchQueue *workerDispatchQueue = [FSTTestDispatchQueue
queueWith:dispatch_queue_create("com.google.firebase.firestore", DISPATCH_QUEUE_SERIAL)];
FSTEmptyCredentialsProvider *credentialsProvider = [[FSTEmptyCredentialsProvider alloc] init];
@@ -142,6 +147,14 @@ NS_ASSUME_NONNULL_BEGIN
return firestore;
}
+- (void)waitForIdleFirestore:(FIRFirestore *)firestore {
+ XCTestExpectation *expectation = [self expectationWithDescription:@"idle"];
+ // Note that we wait on any task that is scheduled with a delay of 60s. Currently, the idle
+ // timeout is the only task that uses this delay.
+ [((FSTTestDispatchQueue *)firestore.workerDispatchQueue) fulfillOnExecution:expectation];
+ [self awaitExpectations];
+}
+
- (void)shutdownFirestore:(FIRFirestore *)firestore {
XCTestExpectation *shutdownCompletion = [self expectationWithDescription:@"shutdown"];
[firestore shutdownWithCompletion:^(NSError *_Nullable error) {
@@ -222,6 +235,27 @@ NS_ASSUME_NONNULL_BEGIN
return result;
}
+- (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)ref
+ requireOnline:(BOOL)requireOnline {
+ __block FIRDocumentSnapshot *result;
+
+ XCTestExpectation *expectation = [self expectationWithDescription:@"listener"];
+ id<FIRListenerRegistration> listener = [ref
+ addSnapshotListenerWithOptions:[[FIRDocumentListenOptions options] includeMetadataChanges:YES]
+ listener:^(FIRDocumentSnapshot *snapshot, NSError *error) {
+ XCTAssertNil(error);
+ if (!requireOnline || !snapshot.metadata.fromCache) {
+ result = snapshot;
+ [expectation fulfill];
+ }
+ }];
+
+ [self awaitExpectations];
+ [listener remove];
+
+ return result;
+}
+
- (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
XCTestExpectation *expectation = [self expectationWithDescription:@"setData"];
[ref setData:data