Skip to content

Commit 09010cf

Browse files
mikelehenwilhuff
authored andcommitted
Fix a couple small issues I tripped over today. (#2806)
* Fix a couple small issues I tripped over today. 1. Fix primeBackend so it uses an isolated FIRFirestore* instance. I ran into an issue where tests that try to change .settings would fail if they were the very first test run, since primeBackend had already configured the client and so settings could no longer be changed. 2. Remove FIRFirestore.client and make api::Firestore.client() assert client is configured.
1 parent 9d0f07b commit 09010cf

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ - (void)setUp {
8585
[super setUp];
8686

8787
[self clearPersistence];
88+
[self primeBackend];
8889

8990
_firestores = [NSMutableArray array];
9091
self.db = [self firestore];
@@ -202,14 +203,13 @@ - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
202203

203204
[_firestores addObject:firestore];
204205

205-
[self primeBackend:firestore];
206-
207206
return firestore;
208207
}
209208

210-
- (void)primeBackend:(FIRFirestore *)db {
209+
- (void)primeBackend {
211210
static dispatch_once_t onceToken;
212211
dispatch_once(&onceToken, ^{
212+
FIRFirestore *db = [self firestore];
213213
XCTestExpectation *watchInitialized =
214214
[self expectationWithDescription:@"Prime backend: Watch initialized"];
215215
__block XCTestExpectation *watchUpdateReceived;
@@ -247,6 +247,8 @@ - (void)primeBackend:(FIRFirestore *)db {
247247
}];
248248

249249
[listenerRegistration remove];
250+
251+
[self shutdownFirestore:db];
250252
});
251253
}
252254

@@ -393,14 +395,13 @@ - (void)mergeDocumentRef:(FIRDocumentReference *)ref
393395
}
394396

395397
- (void)disableNetwork {
396-
[self.db.client
398+
[self.db
397399
disableNetworkWithCompletion:[self completionForExpectationWithName:@"Disable Network."]];
398400
[self awaitExpectations];
399401
}
400402

401403
- (void)enableNetwork {
402-
[self.db.client
403-
enableNetworkWithCompletion:[self completionForExpectationWithName:@"Enable Network."]];
404+
[self.db enableNetworkWithCompletion:[self completionForExpectationWithName:@"Enable Network."]];
404405
[self awaitExpectations];
405406
}
406407

Firestore/Source/API/FIRFirestore+Internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ NS_ASSUME_NONNULL_BEGIN
6868

6969
// FIRFirestore ownes the DatabaseId instance.
7070
@property(nonatomic, assign, readonly) const firebase::firestore::model::DatabaseId *databaseID;
71-
@property(nonatomic, strong, readonly) FSTFirestoreClient *client;
7271
@property(nonatomic, strong, readonly) FSTUserDataConverter *dataConverter;
7372

7473
@end

Firestore/Source/API/FIRFirestore.mm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,6 @@ - (void)setSettings:(FIRFirestoreSettings *)settings {
174174
_firestore->set_settings(settings);
175175
}
176176

177-
/**
178-
* Ensures that the FirestoreClient is configured and returns it.
179-
*/
180-
- (FSTFirestoreClient *)client {
181-
return _firestore->client();
182-
}
183-
184177
- (FIRCollectionReference *)collectionWithPath:(NSString *)collectionPath {
185178
if (!collectionPath) {
186179
ThrowInvalidArgument("Collection path cannot be nil.");

Firestore/Source/API/FIRQuery.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ - (void)getDocumentsWithSource:(FIRFirestoreSource)publicSource
121121
NSError *_Nullable error))completion {
122122
Source source = MakeSource(publicSource);
123123
if (source == Source::Cache) {
124-
[self.firestore.client getDocumentsFromLocalCache:self completion:completion];
124+
[self.firestore.wrapped->client() getDocumentsFromLocalCache:self completion:completion];
125125
return;
126126
}
127127

Firestore/Source/API/FIRWriteBatch.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ - (void)commit {
133133
- (void)commitWithCompletion:(nullable void (^)(NSError *_Nullable error))completion {
134134
[self verifyNotCommitted];
135135
self.committed = TRUE;
136-
[self.firestore.client writeMutations:std::move(_mutations) completion:completion];
136+
[self.firestore.wrapped->client() writeMutations:std::move(_mutations) completion:completion];
137137
}
138138

139139
- (void)verifyNotCommitted {

Firestore/core/src/firebase/firestore/api/firestore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
3333
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
3434
#include "Firestore/core/src/firebase/firestore/util/async_queue.h"
35+
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
3536

3637
NS_ASSUME_NONNULL_BEGIN
3738

@@ -75,6 +76,7 @@ class Firestore {
7576
}
7677

7778
FSTFirestoreClient* client() {
79+
HARD_ASSERT(client_, "Client is not yet configured.");
7880
return client_;
7981
}
8082

0 commit comments

Comments
 (0)