Skip to content

Commit 9e7545a

Browse files
committed
finish integration tests
1 parent 8c5d247 commit 9e7545a

File tree

1 file changed

+131
-1
lines changed

1 file changed

+131
-1
lines changed

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

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ apiDescribe('PersistentCacheIndexManager', persistence => {
164164
}));
165165
});
166166

167-
describe.only('deleteAllPersistentCacheIndexes()', () => {
167+
describe('deleteAllPersistentCacheIndexes()', () => {
168168
it('should return successfully', () =>
169169
withTestDb(persistence, async db => {
170170
const indexManager = getPersistentCacheIndexManager(db)!;
@@ -392,6 +392,136 @@ apiDescribe('PersistentCacheIndexManager', persistence => {
392392
});
393393
});
394394

395+
it('Indexes can be deleted while index auto-creation is enabled', async () => {
396+
const testDocs = partitionedTestDocs({
397+
FooMatches: {
398+
documentData: { foo: 'match' },
399+
documentCount: 2
400+
},
401+
BarMatches: {
402+
documentData: { bar: 'match' },
403+
documentCount: 3
404+
},
405+
NeitherFooNorBarMatch: {
406+
documentData: { foo: 'nomatch', bar: 'nomatch' },
407+
documentCount: 5
408+
}
409+
});
410+
411+
return withTestCollection(persistence, testDocs, async (coll, db) => {
412+
const indexManager = getPersistentCacheIndexManager(db)!;
413+
expect(indexManager, 'indexManager').is.not.null;
414+
enablePersistentCacheIndexAutoCreation(indexManager);
415+
await setPersistentCacheIndexAutoCreationSettings(indexManager, {
416+
indexAutoCreationMinCollectionSize: 0,
417+
relativeIndexReadCostPerDocument: 2
418+
});
419+
420+
// Populate the local cache with the entire collection.
421+
await getDocs(coll);
422+
423+
// Run a query to have an index on the 'foo' field created.
424+
const fooQuery = query(coll, where('foo', '==', 'match'));
425+
{
426+
const fooSnapshot = await getDocsFromCache(fooQuery);
427+
expect(fooSnapshot.size, 'fooSnapshot.size').to.equal(2);
428+
expect(
429+
await getQueryIndexType(fooQuery),
430+
'getQueryIndexType(fooQuery)'
431+
).to.equal('full');
432+
}
433+
434+
// Run a query to have an index on the 'bar' field created.
435+
const barQuery = query(coll, where('bar', '==', 'match'));
436+
{
437+
const barSnapshot = await getDocsFromCache(barQuery);
438+
expect(barSnapshot.size, 'barSnapshot.size').to.equal(3);
439+
expect(
440+
await getQueryIndexType(barQuery),
441+
'getQueryIndexType(barQuery)'
442+
).to.equal('full');
443+
}
444+
445+
// Delete the indexes that were auto-created.
446+
deleteAllPersistentCacheIndexes(indexManager);
447+
expect(
448+
await getQueryIndexType(fooQuery),
449+
'getQueryIndexType(fooQuery) after delete'
450+
).to.equal('none');
451+
expect(
452+
await getQueryIndexType(barQuery),
453+
'getQueryIndexType(barQuery) after delete'
454+
).to.equal('none');
455+
});
456+
});
457+
458+
it('Indexes can be deleted while index auto-creation is disabled', async () => {
459+
const testDocs = partitionedTestDocs({
460+
FooMatches: {
461+
documentData: { foo: 'match' },
462+
documentCount: 2
463+
},
464+
BarMatches: {
465+
documentData: { bar: 'match' },
466+
documentCount: 3
467+
},
468+
NeitherFooNorBarMatch: {
469+
documentData: { foo: 'nomatch', bar: 'nomatch' },
470+
documentCount: 5
471+
}
472+
});
473+
474+
return withTestCollection(persistence, testDocs, async (coll, db) => {
475+
const indexManager = getPersistentCacheIndexManager(db)!;
476+
expect(indexManager, 'indexManager').is.not.null;
477+
enablePersistentCacheIndexAutoCreation(indexManager);
478+
await setPersistentCacheIndexAutoCreationSettings(indexManager, {
479+
indexAutoCreationMinCollectionSize: 0,
480+
relativeIndexReadCostPerDocument: 2
481+
});
482+
483+
// Populate the local cache with the entire collection.
484+
await getDocs(coll);
485+
486+
// Run a query to have an index on the 'foo' field created.
487+
const fooQuery = query(coll, where('foo', '==', 'match'));
488+
{
489+
const fooSnapshot = await getDocsFromCache(fooQuery);
490+
expect(fooSnapshot.size, 'fooSnapshot.size').to.equal(2);
491+
expect(
492+
await getQueryIndexType(fooQuery),
493+
'getQueryIndexType(fooQuery)'
494+
).to.equal('full');
495+
}
496+
497+
// Run a query to have an index on the 'bar' field created.
498+
const barQuery = query(coll, where('bar', '==', 'match'));
499+
{
500+
const barSnapshot = await getDocsFromCache(barQuery);
501+
expect(barSnapshot.size, 'barSnapshot.size').to.equal(3);
502+
expect(
503+
await getQueryIndexType(barQuery),
504+
'getQueryIndexType(barQuery)'
505+
).to.equal('full');
506+
}
507+
508+
// Disable index auto-creation so that the later step can verify that
509+
// indexes can be deleted even while index auto-creation is disabled.
510+
disablePersistentCacheIndexAutoCreation(indexManager);
511+
512+
// Delete the indexes that were auto-created.
513+
deleteAllPersistentCacheIndexes(indexManager);
514+
expect(
515+
await getQueryIndexType(fooQuery),
516+
'getQueryIndexType(fooQuery) after delete'
517+
).to.equal('none');
518+
expect(
519+
await getQueryIndexType(barQuery),
520+
'getQueryIndexType(barQuery) after delete'
521+
).to.equal('none');
522+
});
523+
});
524+
395525
async function testIndexesGetAutoCreated(config: {
396526
documentCounts: { matching: number; notMatching: number };
397527
expectedIndexAutoCreated: boolean;

0 commit comments

Comments
 (0)