@@ -9,7 +9,7 @@ import { EventEmitter } from 'ws';
99
1010import { V1Namespace , V1NamespaceList , V1ObjectMeta , V1Pod , V1ListMeta } from './api' ;
1111import { deleteObject , ListWatch , deleteItems } from './cache' ;
12- import { ADD , UPDATE , DELETE , ListPromise } from './informer' ;
12+ import { ADD , UPDATE , DELETE , ERROR , ListPromise } from './informer' ;
1313
1414use ( chaiAsPromised ) ;
1515
@@ -886,6 +886,63 @@ describe('ListWatchCache', () => {
886886
887887 mock . verify ( fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ) . twice ( ) ;
888888 } ) ;
889+
890+ it ( 'does not auto-restart after an error' , async ( ) => {
891+
892+ const fakeWatch = mock . mock ( Watch ) ;
893+ const list : V1Pod [ ] = [
894+ {
895+ metadata : {
896+ name : 'name1' ,
897+ namespace : 'ns1' ,
898+ } as V1ObjectMeta ,
899+ } as V1Pod ,
900+ {
901+ metadata : {
902+ name : 'name2' ,
903+ namespace : 'ns2' ,
904+ } as V1ObjectMeta ,
905+ } as V1Pod ,
906+ ] ;
907+ const listObj = {
908+ metadata : {
909+ resourceVersion : '12345' ,
910+ } as V1ListMeta ,
911+ items : list ,
912+ } as V1NamespaceList ;
913+
914+ const listFn : ListPromise < V1Namespace > = function ( ) : Promise < {
915+ response : http . IncomingMessage ;
916+ body : V1NamespaceList ;
917+ } > {
918+ return new Promise < { response : http . IncomingMessage ; body : V1NamespaceList } > (
919+ ( resolve , reject ) => {
920+ resolve ( { response : { } as http . IncomingMessage , body : listObj } ) ;
921+ } ,
922+ ) ;
923+ } ;
924+ let promise = new Promise ( ( resolve ) => {
925+ mock . when (
926+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
927+ ) . thenCall ( ( ) => {
928+ resolve ( new FakeRequest ( ) ) ;
929+ } ) ;
930+ } ) ;
931+
932+ const cache = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn ) ;
933+ await promise ;
934+
935+ let errorEmitted = false ;
936+ cache . on ( ERROR , ( ) => errorEmitted = true ) ;
937+
938+ const [ , , , doneHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
939+
940+ const error = new Error ( 'testing' ) ;
941+ await doneHandler ( error ) ;
942+
943+ mock . verify ( fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ) . once ( ) ;
944+ expect ( errorEmitted ) . to . equal ( true ) ;
945+ } ) ;
889946} ) ;
890947
891948describe ( 'delete items' , ( ) => {
0 commit comments