@@ -575,4 +575,66 @@ apiDescribe('PersistentCacheIndexManager', persistence => {
575
575
} ) ;
576
576
}
577
577
} ) ;
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
+ } ) ;
578
640
} ) ;
0 commit comments