Skip to content

Adding call to clearPersistence() into AsyncQueue #1740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { LogLevel } from '../util/log';
import { AutoId } from '../util/misc';
import * as objUtils from '../util/obj';
import { Rejecter, Resolver } from '../util/promise';
import { Deferred } from './../util/promise';
import { FieldPath as ExternalFieldPath } from './field_path';

import {
Expand Down Expand Up @@ -436,7 +437,16 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
const persistenceKey = IndexedDbPersistence.buildStoragePrefix(
this.makeDatabaseInfo()
);
return IndexedDbPersistence.clearPersistence(persistenceKey);
const deferred = new Deferred<void>();
this._queue.enqueueAndForget(async () => {
try {
await IndexedDbPersistence.clearPersistence(persistenceKey);
deferred.resolve();
} catch (e) {
deferred.reject(e);
}
});
return deferred.promise;
}

ensureClientConfigured(): FirestoreClient {
Expand Down
22 changes: 22 additions & 0 deletions packages/firestore/test/integration/api/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as chaiAsPromised from 'chai-as-promised';
import * as firestore from '@firebase/firestore-types';
import { expect } from 'chai';

import { SimpleDb } from '../../../src/local/simple_db';
import { fail } from '../../../src/util/assert';
import { Code } from '../../../src/util/error';
import { query } from '../../util/api_helpers';
Expand Down Expand Up @@ -971,6 +972,27 @@ apiDescribe('Database', persistence => {
}
);

(persistence ? it : it.skip)(
'will reject the promise if clear persistence fails',
async () => {
await withTestDoc(persistence, async docRef => {
const oldDelete = SimpleDb.delete;
try {
SimpleDb.delete = (name: string): Promise<void> => {
return Promise.reject('Failed to delete the database.');
};
const firestore = docRef.firestore;
await firestore.app.delete();
await expect(
clearPersistence(firestore)
).to.eventually.be.rejectedWith('Failed to delete the database.');
} finally {
SimpleDb.delete = oldDelete;
}
});
}
);

it('can not clear persistence if the client has been initialized', async () => {
await withTestDoc(persistence, async docRef => {
const firestore = docRef.firestore;
Expand Down