Skip to content

Commit

Permalink
Revert: IndexedDB recovery for handleUserChange
Browse files Browse the repository at this point in the history
Reverts #3087
Fixes #3179
  • Loading branch information
schmidt-sebastian committed Jun 9, 2020
1 parent 1e3721c commit caebb4b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class FirestoreClient {
persistenceResult
).then(initializationDone.resolve, initializationDone.reject);
} else {
this.asyncQueue.enqueueRetryable(() => {
this.asyncQueue.enqueueAndForget(() => {
return this.handleCredentialChange(user);
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,15 +862,15 @@ export class SyncEngine implements RemoteSyncer {

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

if (userChanged) {
const result = await this.localStore.handleUserChange(user);
this.currentUser = user;

// Fails tasks waiting for pending writes requested by previous user.
this.rejectOutstandingPendingWritesCallbacks(
"'waitForPendingWrites' promise is rejected due to a user change."
);

const result = await this.localStore.handleUserChange(user);
// TODO(b/114226417): Consider calling this only in the primary tab.
this.sharedClientState.handleUserChange(
user,
Expand Down
37 changes: 0 additions & 37 deletions packages/firestore/test/unit/specs/recovery_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,41 +709,4 @@ describeSpec('Persistence Recovery', ['no-ios', 'no-android'], () => {
removed: [doc1]
});
});

specTest(
'User change handles transaction failures (with recovery)',
['durable-persistence'],
() => {
const query = Query.atPath(path('collection'));
const doc1 = doc(
'collection/key1',
0,
{ foo: 'a' },
{ hasLocalMutations: true }
);
return spec()
.changeUser('user1')
.userSets('collection/key1', { foo: 'a' })
.userListens(query)
.expectEvents(query, {
added: [doc1],
fromCache: true,
hasPendingWrites: true
})
.failDatabaseTransactions('Handle user change')
.changeUser('user2')
.recoverDatabase()
.runTimer(TimerId.AsyncQueueRetry)
.expectEvents(query, { removed: [doc1], fromCache: true })
.failDatabaseTransactions('Handle user change')
.changeUser('user1')
.recoverDatabase()
.runTimer(TimerId.AsyncQueueRetry)
.expectEvents(query, {
added: [doc1],
fromCache: true,
hasPendingWrites: true
});
}
);
});
16 changes: 4 additions & 12 deletions packages/firestore/test/unit/specs/spec_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,19 +714,11 @@ abstract class TestRunner {
return Promise.resolve();
}

private async doChangeUser(user: string | null): Promise<void> {
private doChangeUser(user: string | null): Promise<void> {
this.user = new User(user);
const deferred = new Deferred<void>();
await this.queue.enqueueRetryable(async () => {
try {
await this.syncEngine.handleCredentialChange(this.user);
} finally {
// Resolve the deferred Promise even if the operation failed. This allows
// the spec tests to manually retry the failed user change.
deferred.resolve();
}
});
return deferred.promise;
return this.queue.enqueue(() =>
this.syncEngine.handleCredentialChange(this.user)
);
}

private async doFailDatabase(
Expand Down

0 comments on commit caebb4b

Please sign in to comment.