@@ -577,6 +577,7 @@ describe('ListWatchCache', () => {
577577 expect ( cache . list ( 'ns2' ) . length ) . to . equal ( 0 ) ;
578578 expect ( cache . get ( 'name2' , 'ns2' ) ) . to . equal ( undefined ) ;
579579 } ) ;
580+
580581 it ( 'should delete an object correctly' , ( ) => {
581582 const list : V1Pod [ ] = [
582583 {
@@ -614,6 +615,7 @@ describe('ListWatchCache', () => {
614615 } as V1Pod ) ;
615616 expect ( list . length ) . to . equal ( 1 ) ;
616617 } ) ;
618+
617619 it ( 'should not call handlers which have been unregistered' , async ( ) => {
618620 const fakeWatch = mock . mock ( Watch ) ;
619621 const list : V1Namespace [ ] = [ ] ;
@@ -721,6 +723,7 @@ describe('ListWatchCache', () => {
721723
722724 expect ( addedList . length ) . to . equal ( 1 ) ;
723725 } ) ;
726+
724727 it ( 'should resolve start promise after seeding the cache' , async ( ) => {
725728 const fakeWatch = mock . mock ( Watch ) ;
726729 const list : V1Namespace [ ] = [
@@ -823,6 +826,66 @@ describe('ListWatchCache', () => {
823826 expect ( addedList1 . length ) . to . equal ( 2 ) ;
824827 expect ( addedList2 . length ) . to . equal ( 1 ) ;
825828 } ) ;
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+ } ) ;
826889} ) ;
827890
828891describe ( 'delete items' , ( ) => {
0 commit comments