Skip to content

Commit 3240d86

Browse files
Merge caebb4b into 1e3721c
2 parents 1e3721c + caebb4b commit 3240d86

File tree

4 files changed

+8
-53
lines changed

4 files changed

+8
-53
lines changed

packages/firestore/src/core/firestore_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class FirestoreClient {
179179
persistenceResult
180180
).then(initializationDone.resolve, initializationDone.reject);
181181
} else {
182-
this.asyncQueue.enqueueRetryable(() => {
182+
this.asyncQueue.enqueueAndForget(() => {
183183
return this.handleCredentialChange(user);
184184
});
185185
}

packages/firestore/src/core/sync_engine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,15 +862,15 @@ export class SyncEngine implements RemoteSyncer {
862862

863863
async handleCredentialChange(user: User): Promise<void> {
864864
const userChanged = !this.currentUser.isEqual(user);
865+
this.currentUser = user;
865866

866867
if (userChanged) {
867-
const result = await this.localStore.handleUserChange(user);
868-
this.currentUser = user;
869-
870868
// Fails tasks waiting for pending writes requested by previous user.
871869
this.rejectOutstandingPendingWritesCallbacks(
872870
"'waitForPendingWrites' promise is rejected due to a user change."
873871
);
872+
873+
const result = await this.localStore.handleUserChange(user);
874874
// TODO(b/114226417): Consider calling this only in the primary tab.
875875
this.sharedClientState.handleUserChange(
876876
user,

packages/firestore/test/unit/specs/recovery_spec.test.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -709,41 +709,4 @@ describeSpec('Persistence Recovery', ['no-ios', 'no-android'], () => {
709709
removed: [doc1]
710710
});
711711
});
712-
713-
specTest(
714-
'User change handles transaction failures (with recovery)',
715-
['durable-persistence'],
716-
() => {
717-
const query = Query.atPath(path('collection'));
718-
const doc1 = doc(
719-
'collection/key1',
720-
0,
721-
{ foo: 'a' },
722-
{ hasLocalMutations: true }
723-
);
724-
return spec()
725-
.changeUser('user1')
726-
.userSets('collection/key1', { foo: 'a' })
727-
.userListens(query)
728-
.expectEvents(query, {
729-
added: [doc1],
730-
fromCache: true,
731-
hasPendingWrites: true
732-
})
733-
.failDatabaseTransactions('Handle user change')
734-
.changeUser('user2')
735-
.recoverDatabase()
736-
.runTimer(TimerId.AsyncQueueRetry)
737-
.expectEvents(query, { removed: [doc1], fromCache: true })
738-
.failDatabaseTransactions('Handle user change')
739-
.changeUser('user1')
740-
.recoverDatabase()
741-
.runTimer(TimerId.AsyncQueueRetry)
742-
.expectEvents(query, {
743-
added: [doc1],
744-
fromCache: true,
745-
hasPendingWrites: true
746-
});
747-
}
748-
);
749712
});

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,19 +714,11 @@ abstract class TestRunner {
714714
return Promise.resolve();
715715
}
716716

717-
private async doChangeUser(user: string | null): Promise<void> {
717+
private doChangeUser(user: string | null): Promise<void> {
718718
this.user = new User(user);
719-
const deferred = new Deferred<void>();
720-
await this.queue.enqueueRetryable(async () => {
721-
try {
722-
await this.syncEngine.handleCredentialChange(this.user);
723-
} finally {
724-
// Resolve the deferred Promise even if the operation failed. This allows
725-
// the spec tests to manually retry the failed user change.
726-
deferred.resolve();
727-
}
728-
});
729-
return deferred.promise;
719+
return this.queue.enqueue(() =>
720+
this.syncEngine.handleCredentialChange(this.user)
721+
);
730722
}
731723

732724
private async doFailDatabase(

0 commit comments

Comments
 (0)