Skip to content

Commit 2ea1fad

Browse files
committed
Fix error and polishing.
1 parent 7b9d18d commit 2ea1fad

File tree

4 files changed

+30
-41
lines changed

4 files changed

+30
-41
lines changed

packages/firestore/src/api/database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export function configureFirestore(firestore: Firestore): void {
287287
}
288288

289289
/**
290-
* Attempts to enable the LRU garbage collector for memory persistence.
290+
* Attempts to enable LRU garbage collection for memory persistence.
291291
*
292292
* Must be called before any other functions (other than
293293
* {@link initializeFirestore}, {@link (getFirestore:1)} or
@@ -300,8 +300,8 @@ export function configureFirestore(firestore: Firestore): void {
300300
* garbage collector. Documents will be collected when their total size exceeds
301301
* `Settings.cacheSizeBytes`, with least recently used documents get removed first.
302302
*
303-
* @param firestore - The {@link Firestore} instance to enable persistence for.
304-
* @returns A `Promise` that represents successfully enabling persistent storage.
303+
* @param firestore - The {@link Firestore} instance to enable LRU garbage collection for.
304+
* @returns A `Promise` that represents successfully enabling LRU garbage collection.
305305
*/
306306
export function enableMemoryLRUGarbageCollection(
307307
firestore: Firestore

packages/firestore/test/integration/api/database.test.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Deferred } from '@firebase/util';
2020
import { expect, use } from 'chai';
2121
import chaiAsPromised from 'chai-as-promised';
2222

23-
import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../../../src/local/lru_garbage_collector_impl';
2423
import { EventsAccumulator } from '../util/events_accumulator';
2524
import {
2625
addDoc,
@@ -68,7 +67,7 @@ import {
6867
} from '../util/firebase_export';
6968
import {
7069
apiDescribe,
71-
withEnsuredGcTestDb,
70+
withEnsuredLruGcTestDb,
7271
withTestCollection,
7372
withTestDbsSettings,
7473
withTestDb,
@@ -1756,19 +1755,15 @@ apiDescribe('Database', (persistence: boolean) => {
17561755

17571756
it('Can get document from cache with GC enabled.', () => {
17581757
const initialData = { key: 'value' };
1759-
return withEnsuredGcTestDb(
1760-
persistence,
1761-
LRU_MINIMUM_CACHE_SIZE_BYTES,
1762-
async db => {
1763-
const docRef = doc(collection(db, 'test-collection'));
1764-
await setDoc(docRef, initialData);
1765-
return getDoc(docRef).then(doc => {
1766-
expect(doc.exists()).to.be.true;
1767-
expect(doc.metadata.fromCache).to.be.false;
1768-
expect(doc.metadata.hasPendingWrites).to.be.false;
1769-
expect(doc.data()).to.deep.equal(initialData);
1770-
});
1771-
}
1772-
);
1758+
return withEnsuredLruGcTestDb(persistence, async db => {
1759+
const docRef = doc(collection(db, 'test-collection'));
1760+
await setDoc(docRef, initialData);
1761+
return getDoc(docRef).then(doc => {
1762+
expect(doc.exists()).to.be.true;
1763+
expect(doc.metadata.fromCache).to.be.false;
1764+
expect(doc.metadata.hasPendingWrites).to.be.false;
1765+
expect(doc.data()).to.deep.equal(initialData);
1766+
});
1767+
});
17731768
});
17741769
});

packages/firestore/test/integration/api/get_options.test.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { expect } from 'chai';
1919

20-
import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../../../src/local/lru_garbage_collector_impl';
2120
import {
2221
collection,
2322
deleteDoc,
@@ -37,7 +36,7 @@ import {
3736
apiDescribe,
3837
withTestCollection,
3938
withTestDocAndInitialData,
40-
withEnsuredGcTestDb
39+
withEnsuredLruGcTestDb
4140
} from '../util/helpers';
4241

4342
apiDescribe('GetOptions', (persistence: boolean) => {
@@ -72,23 +71,19 @@ apiDescribe('GetOptions', (persistence: boolean) => {
7271
it('get document while offline with default get options', () => {
7372
const initialData = { key: 'value' };
7473
// Use an instance with Gc turned on.
75-
return withEnsuredGcTestDb(
76-
persistence,
77-
LRU_MINIMUM_CACHE_SIZE_BYTES,
78-
async db => {
79-
const docRef = doc(collection(db, 'test-collection'));
80-
await setDoc(docRef, initialData);
81-
return getDoc(docRef)
82-
.then(() => disableNetwork(db))
83-
.then(() => getDoc(docRef))
84-
.then(doc => {
85-
expect(doc.exists()).to.be.true;
86-
expect(doc.metadata.fromCache).to.be.true;
87-
expect(doc.metadata.hasPendingWrites).to.be.false;
88-
expect(doc.data()).to.deep.equal(initialData);
89-
});
90-
}
91-
);
74+
return withEnsuredLruGcTestDb(persistence, async db => {
75+
const docRef = doc(collection(db, 'test-collection'));
76+
await setDoc(docRef, initialData);
77+
return getDoc(docRef)
78+
.then(() => disableNetwork(db))
79+
.then(() => getDoc(docRef))
80+
.then(doc => {
81+
expect(doc.exists()).to.be.true;
82+
expect(doc.metadata.fromCache).to.be.true;
83+
expect(doc.metadata.hasPendingWrites).to.be.false;
84+
expect(doc.data()).to.deep.equal(initialData);
85+
});
86+
});
9287
});
9388

9489
it('get collection while offline with default get options', () => {

packages/firestore/test/integration/util/helpers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,14 @@ export function withTestDb(
142142
});
143143
}
144144

145-
export function withEnsuredGcTestDb(
145+
export function withEnsuredLruGcTestDb(
146146
persistence: boolean,
147-
sizeBytes: number,
148147
fn: (db: Firestore) => Promise<void>
149148
): Promise<void> {
150149
return withTestDbsSettings(
151150
persistence,
152151
DEFAULT_PROJECT_ID,
153-
{ ...DEFAULT_SETTINGS, cacheSizeBytes: sizeBytes },
152+
{ ...DEFAULT_SETTINGS, cacheSizeBytes: 1 * 1024 * 1024 },
154153
1,
155154
async ([db]) => {
156155
if (!persistence) {

0 commit comments

Comments
 (0)