@@ -1100,6 +1100,75 @@ describe('ListWatchCache', () => {
1100
1100
expect ( listCalls ) . to . be . equal ( 2 ) ;
1101
1101
} ) ;
1102
1102
1103
+ it ( 'should list if the watch cannot be restarted from the latest resourceVersion with an ERROR event' , async ( ) => {
1104
+ const fakeWatch = mock . mock ( Watch ) ;
1105
+ const list : V1Pod [ ] = [ ] ;
1106
+ const listObj = {
1107
+ metadata : {
1108
+ resourceVersion : '12345' ,
1109
+ } as V1ListMeta ,
1110
+ items : list ,
1111
+ } as V1NamespaceList ;
1112
+
1113
+ let listCalls = 0 ;
1114
+ const listFn : ListPromise < V1Namespace > = function ( ) : Promise < V1NamespaceList > {
1115
+ return new Promise < V1NamespaceList > ( ( resolve ) => {
1116
+ listCalls ++ ;
1117
+ resolve ( listObj ) ;
1118
+ } ) ;
1119
+ } ;
1120
+ let promise = new Promise ( ( resolve ) => {
1121
+ mock . when (
1122
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1123
+ ) . thenCall ( ( ) => {
1124
+ resolve ( new AbortController ( ) ) ;
1125
+ } ) ;
1126
+ } ) ;
1127
+
1128
+ const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn , false ) ;
1129
+
1130
+ informer . start ( ) ;
1131
+ await promise ;
1132
+
1133
+ const [ , , watchHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
1134
+ watchHandler (
1135
+ 'ADDED' ,
1136
+ {
1137
+ metadata : {
1138
+ name : 'name3' ,
1139
+ } as V1ObjectMeta ,
1140
+ } as V1Namespace ,
1141
+ { metadata : { resourceVersion : '23456' } } ,
1142
+ ) ;
1143
+
1144
+ await informer . stop ( ) ;
1145
+
1146
+ let errorEmitted = false ;
1147
+ informer . on ( 'error' , ( ) => ( errorEmitted = true ) ) ;
1148
+
1149
+ promise = new Promise ( ( resolve ) => {
1150
+ mock . when (
1151
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1152
+ ) . thenCall ( ( ) => {
1153
+ resolve ( new AbortController ( ) ) ;
1154
+ } ) ;
1155
+ } ) ;
1156
+
1157
+ informer . start ( ) ;
1158
+ await promise ;
1159
+
1160
+ const [ , , watchHandler2 , doneHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
1161
+ watchHandler2 ( 'ERROR' , {
1162
+ code : 410 ,
1163
+ } ) ;
1164
+ doneHandler ( undefined ) ;
1165
+ mock . verify (
1166
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1167
+ ) . twice ( ) ;
1168
+ expect ( errorEmitted ) . to . equal ( false ) ;
1169
+ expect ( listCalls ) . to . be . equal ( 2 ) ;
1170
+ } ) ;
1171
+
1103
1172
it ( 'should send label selector' , async ( ) => {
1104
1173
const APP_LABEL_SELECTOR = 'app=foo' ;
1105
1174
0 commit comments