@@ -577,6 +577,7 @@ describe('ListWatchCache', () => {
577
577
expect ( cache . list ( 'ns2' ) . length ) . to . equal ( 0 ) ;
578
578
expect ( cache . get ( 'name2' , 'ns2' ) ) . to . equal ( undefined ) ;
579
579
} ) ;
580
+
580
581
it ( 'should delete an object correctly' , ( ) => {
581
582
const list : V1Pod [ ] = [
582
583
{
@@ -614,6 +615,7 @@ describe('ListWatchCache', () => {
614
615
} as V1Pod ) ;
615
616
expect ( list . length ) . to . equal ( 1 ) ;
616
617
} ) ;
618
+
617
619
it ( 'should not call handlers which have been unregistered' , async ( ) => {
618
620
const fakeWatch = mock . mock ( Watch ) ;
619
621
const list : V1Namespace [ ] = [ ] ;
@@ -721,6 +723,7 @@ describe('ListWatchCache', () => {
721
723
722
724
expect ( addedList . length ) . to . equal ( 1 ) ;
723
725
} ) ;
726
+
724
727
it ( 'should resolve start promise after seeding the cache' , async ( ) => {
725
728
const fakeWatch = mock . mock ( Watch ) ;
726
729
const list : V1Namespace [ ] = [
@@ -823,6 +826,66 @@ describe('ListWatchCache', () => {
823
826
expect ( addedList1 . length ) . to . equal ( 2 ) ;
824
827
expect ( addedList2 . length ) . to . equal ( 1 ) ;
825
828
} ) ;
829
+
830
+ it ( 'should not auto-restart after explicitly stopping until restarted again' , async ( ) => {
831
+
832
+ const fakeWatch = mock . mock ( Watch ) ;
833
+ const list : V1Pod [ ] = [
834
+ {
835
+ metadata : {
836
+ name : 'name1' ,
837
+ namespace : 'ns1' ,
838
+ } as V1ObjectMeta ,
839
+ } as V1Pod ,
840
+ {
841
+ metadata : {
842
+ name : 'name2' ,
843
+ namespace : 'ns2' ,
844
+ } as V1ObjectMeta ,
845
+ } as V1Pod ,
846
+ ] ;
847
+ const listObj = {
848
+ metadata : {
849
+ resourceVersion : '12345' ,
850
+ } as V1ListMeta ,
851
+ items : list ,
852
+ } as V1NamespaceList ;
853
+
854
+ const listFn : ListPromise < V1Namespace > = function ( ) : Promise < {
855
+ response : http . IncomingMessage ;
856
+ body : V1NamespaceList ;
857
+ } > {
858
+ return new Promise < { response : http . IncomingMessage ; body : V1NamespaceList } > (
859
+ ( resolve , reject ) => {
860
+ resolve ( { response : { } as http . IncomingMessage , body : listObj } ) ;
861
+ } ,
862
+ ) ;
863
+ } ;
864
+ let promise = new Promise ( ( resolve ) => {
865
+ mock . when (
866
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
867
+ ) . thenCall ( ( ) => {
868
+ resolve ( new FakeRequest ( ) ) ;
869
+ } ) ;
870
+ } ) ;
871
+
872
+ const cache = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
873
+ await promise ;
874
+
875
+ const [ , , , doneHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
876
+
877
+ // stop the informer
878
+ cache . stop ( ) ;
879
+
880
+ await doneHandler ( null ) ;
881
+
882
+ mock . verify ( fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ) . once ( ) ;
883
+
884
+ // restart the informer
885
+ await cache . start ( ) ;
886
+
887
+ mock . verify ( fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ) . twice ( ) ;
888
+ } ) ;
826
889
} ) ;
827
890
828
891
describe ( 'delete items' , ( ) => {
0 commit comments