Skip to content

Commit 5b31033

Browse files
committed
addressing comments #1
1 parent c3b37c9 commit 5b31033

File tree

6 files changed

+32
-36
lines changed

6 files changed

+32
-36
lines changed

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -1417,17 +1417,16 @@ - (void)testWaitForPendingWritesCompletes {
14171417
}
14181418

14191419
- (void)testWaitForPendingWritesFailsWhenUserChanges {
1420-
FIRApp *app = testutil::AppForUnitTesting(util::MakeString([FSTIntegrationTestCase projectID]));
1421-
FIRFirestore *firestore = [self firestoreWithApp:app];
1420+
// FIRApp *app = testutil::AppForUnitTesting(util::MakeString([FSTIntegrationTestCase
1421+
// projectID]));
1422+
FIRFirestore *firestore = self.db;
14221423

1423-
[firestore
1424-
disableNetworkWithCompletion:[self completionForExpectationWithName:@"Disable network"]];
1425-
[self awaitExpectations];
1424+
[self disableNetwork];
14261425

14271426
// Writes to local to prevent immediate call to the completion of waitForPendingWrites.
14281427
NSDictionary<NSString *, id> *data =
1429-
@{@"owner" : @{@"name" : @"Andy", @"email" : @"abc@xyz.com"}};
1430-
[[firestore documentWithPath:@"abc/123"] setData:data];
1428+
@{@"owner" : @{@"name" : @"Andy", @"email" : @"abc@example.com"}};
1429+
[[self documentRef] setData:data];
14311430

14321431
XCTestExpectation *expectation = [self expectationWithDescription:@"waitForPendingWrites"];
14331432
[firestore waitForPendingWritesWithCompletion:^(NSError *_Nullable error) {
@@ -1442,8 +1441,7 @@ - (void)testWaitForPendingWritesFailsWhenUserChanges {
14421441
}
14431442

14441443
- (void)testWaitForPendingWritesCompletesWhenOfflineIfNoPending {
1445-
FIRDocumentReference *doc = [self documentRef];
1446-
FIRFirestore *firestore = doc.firestore;
1444+
FIRFirestore *firestore = self.db;
14471445

14481446
[firestore
14491447
disableNetworkWithCompletion:[self completionForExpectationWithName:@"Disable network"]];

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
// Behaves the same as `EmptyCredentialsProvider` except it can also trigger a user
8787
// change.
88-
class MockCredentialsProvider : public EmptyCredentialsProvider {
88+
class FakeCredentialsProvider : public EmptyCredentialsProvider {
8989
public:
9090
void SetCredentialChangeListener(CredentialChangeListener changeListener) override {
9191
if (changeListener) {
@@ -106,13 +106,13 @@ void ChangeUser(NSString *new_id) {
106106

107107
@implementation FSTIntegrationTestCase {
108108
NSMutableArray<FIRFirestore *> *_firestores;
109-
std::shared_ptr<MockCredentialsProvider> _mockCredProdiver;
109+
std::shared_ptr<FakeCredentialsProvider> _fakeCredentialsProvider;
110110
}
111111

112112
- (void)setUp {
113113
[super setUp];
114114

115-
_mockCredProdiver = std::make_shared<MockCredentialsProvider>();
115+
_fakeCredentialsProvider = std::make_shared<FakeCredentialsProvider>();
116116

117117
[self clearPersistenceOnce];
118118
[self primeBackend];
@@ -271,7 +271,7 @@ - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
271271
FIRFirestore *firestore =
272272
[[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID)
273273
persistenceKey:util::MakeString(persistenceKey)
274-
credentialsProvider:_mockCredProdiver
274+
credentialsProvider:_fakeCredentialsProvider
275275
workerQueue:std::move(workerQueue)
276276
firebaseApp:app
277277
instanceRegistry:nil];
@@ -282,7 +282,7 @@ - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
282282
}
283283

284284
- (void)triggerUserChangeWithUid:(NSString *)uid {
285-
_mockCredProdiver->ChangeUser(uid);
285+
_fakeCredentialsProvider->ChangeUser(uid);
286286
}
287287

288288
- (void)primeBackend {

Firestore/Source/API/FIRFirestore+Internal.h

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ NS_ASSUME_NONNULL_BEGIN
9090

9191
- (void)shutdownInternalWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
9292

93+
/**
94+
* Waits until all currently pending writes for the active user have been acknowledged by the
95+
* backend.
96+
*
97+
* The completion block is called immediately without error if there are no outstanding writes.
98+
* Otherwise, the completion block is called when all previously issued writes (including those
99+
* written in a previous app session) have been acknowledged by the backend. The completion
100+
* block does not wait for writes that were added after the method is called. If you
101+
* wish to wait for additional writes, you have to call `waitForPendingWritesWithCompletion`
102+
* again.
103+
*
104+
* Any outstanding `waitForPendingWritesWithCompletion` completion blocks are called with an
105+
* error during user change.
106+
*/
107+
- (void)waitForPendingWritesWithCompletion:(void (^)(NSError *_Nullable error))completion;
108+
93109
- (const std::shared_ptr<util::AsyncQueue> &)workerQueue;
94110

95111
@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;

Firestore/Source/Local/FSTLocalStore.mm

+2-3
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,8 @@ - (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(BatchId)batchID {
428428
}
429429

430430
- (model::BatchId)getHighestUnacknowledgedBatchId {
431-
return self.persistence.run("getHighestUnacknowledgedBatchId", [&]() -> model::BatchId {
432-
return _mutationQueue->GetHighestUnacknowledgedBatchId();
433-
});
431+
return self.persistence.run("getHighestUnacknowledgedBatchId",
432+
[&]() { return _mutationQueue->GetHighestUnacknowledgedBatchId(); });
434433
}
435434

436435
- (FSTQueryData *)allocateQuery:(Query)query {

Firestore/Source/Public/FIRFirestore.h

-16
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,6 @@ NS_SWIFT_NAME(Firestore)
154154
*/
155155
- (FIRWriteBatch *)batch;
156156

157-
/**
158-
* Waits until all currently pending writes for the active user have been acknowledged by the
159-
* backend.
160-
*
161-
* The completion block is called immediately without error if there are no outstanding writes.
162-
* Otherwise, the completion block is called when all previously issued writes (including those
163-
* written in a previous app session) have been acknowledged by the backend. The completion
164-
* block does not wait for writes that were added after the method is called. If you
165-
* wish to wait for additional writes, you have to call `waitForPendingWritesWithCompletion`
166-
* again.
167-
*
168-
* Any outstanding `waitForPendingWritesWithCompletion()` completion blocks are called with an
169-
* error during user change.
170-
*/
171-
- (void)waitForPendingWritesWithCompletion:(void (^)(NSError *_Nullable error))completion;
172-
173157
#pragma mark - Logging
174158

175159
/** Enables or disables logging from the Firestore client. */

Firestore/core/src/firebase/firestore/local/leveldb_mutation_queue.mm

+2-3
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,15 @@ BatchId LoadNextBatchIdFromDb(DB* db) {
383383
util::PrefixSuccessor(LevelDbMutationKey::KeyPrefix(user_id_));
384384

385385
LevelDbMutationKey row_key;
386-
BatchId max_batch_id = kBatchIdUnknown;
387386

388387
it->Seek(next_user_key);
389388
it->Prev();
390389
if (it->Valid() && row_key.Decode(MakeStringView(it->key())) &&
391390
row_key.user_id() == user_id_) {
392-
max_batch_id = row_key.batch_id();
391+
return row_key.batch_id();
393392
}
394393

395-
return max_batch_id;
394+
return kBatchIdUnknown;
396395
}
397396

398397
void LevelDbMutationQueue::PerformConsistencyCheck() {

0 commit comments

Comments
 (0)