Skip to content

Commit 1e95830

Browse files
committed
Merge remote-tracking branch 'origin/master' into ClientSideIndexAutoCreationTestingHooks
2 parents a92925c + 25cda8a commit 1e95830

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,66 @@ apiDescribe('PersistentCacheIndexManager', persistence => {
575575
});
576576
}
577577
});
578+
579+
describe('delete all persistent cache indexes', () => {
580+
it('deleteAllPersistentCacheIndexes() on new instance should succeed', () =>
581+
withTestDb(persistence, async db => {
582+
const indexManager = getPersistentCacheIndexManager(db)!;
583+
deleteAllPersistentCacheIndexes(indexManager);
584+
}));
585+
586+
it('deleteAllPersistentCacheIndexes() should be successful when auto-indexing is enabled', () =>
587+
withTestDb(persistence, async db => {
588+
const indexManager = getPersistentCacheIndexManager(db)!;
589+
enablePersistentCacheIndexAutoCreation(indexManager);
590+
deleteAllPersistentCacheIndexes(indexManager);
591+
}));
592+
593+
it('deleteAllPersistentCacheIndexes() should be successful when auto-indexing is disabled', () =>
594+
withTestDb(persistence, async db => {
595+
const indexManager = getPersistentCacheIndexManager(db)!;
596+
enablePersistentCacheIndexAutoCreation(indexManager);
597+
disablePersistentCacheIndexAutoCreation(indexManager);
598+
deleteAllPersistentCacheIndexes(indexManager);
599+
}));
600+
601+
it('deleteAllPersistentCacheIndexes() after terminate() should throw', () =>
602+
withTestDb(persistence, async db => {
603+
const indexManager = getPersistentCacheIndexManager(db)!;
604+
terminate(db).catch(e => expect.fail(`terminate() failed: ${e}`));
605+
expect(() => deleteAllPersistentCacheIndexes(indexManager)).to.throw(
606+
'The client has already been terminated.'
607+
);
608+
}));
609+
610+
it('query returns correct results when auto-created index has been deleted', () => {
611+
const testDocs = partitionedTestDocs({
612+
matching: { documentData: { match: true }, documentCount: 1 },
613+
nonmatching: { documentData: { match: false }, documentCount: 100 }
614+
});
615+
return withTestCollection(persistence, testDocs, async (coll, db) => {
616+
const indexManager = getPersistentCacheIndexManager(db)!;
617+
enablePersistentCacheIndexAutoCreation(indexManager);
618+
619+
// Populate the local cache with the entire collection's contents.
620+
await getDocs(coll);
621+
622+
// Run a query that matches only one of the documents in the collection;
623+
// this should cause an index to be auto-created.
624+
const query_ = query(coll, where('match', '==', true));
625+
const snapshot1 = await getDocsFromCache(query_);
626+
expect(snapshot1.size).to.equal(1);
627+
628+
// Delete the index
629+
deleteAllPersistentCacheIndexes(indexManager);
630+
631+
// Run the query that matches only one of the documents again, which
632+
// should _still_ return the one and only document that matches. Since
633+
// the public API surface does not reveal whether an index was used,
634+
// there isn't anything else that can be verified.
635+
const snapshot2 = await getDocsFromCache(query_);
636+
expect(snapshot2.size).to.equal(1);
637+
});
638+
});
639+
});
578640
});

0 commit comments

Comments
 (0)