@@ -1096,9 +1096,10 @@ describe('ListWatchCache', () => {
1096
1096
{
1097
1097
metadata : {
1098
1098
name : 'name3' ,
1099
+ resourceVersion : '23456' ,
1099
1100
} as V1ObjectMeta ,
1100
1101
} as V1Namespace ,
1101
- { metadata : { resourceVersion : '23456' } } ,
1102
+ { type : 'ADDED' , metadata : { resourceVersion : '23456' } } ,
1102
1103
) ;
1103
1104
1104
1105
await informer . stop ( ) ;
@@ -1153,9 +1154,91 @@ describe('ListWatchCache', () => {
1153
1154
{
1154
1155
metadata : {
1155
1156
name : 'name3' ,
1157
+ resourceVersion : '23456' ,
1156
1158
} as V1ObjectMeta ,
1157
1159
} as V1Namespace ,
1158
- { metadata : { resourceVersion : '23456' } } ,
1160
+ { type : 'ADDED' , metadata : { resourceVersion : '23456' } } ,
1161
+ ) ;
1162
+
1163
+ await informer . stop ( ) ;
1164
+
1165
+ let errorEmitted = false ;
1166
+ informer . on ( 'error' , ( ) => ( errorEmitted = true ) ) ;
1167
+
1168
+ promise = new Promise ( ( resolve ) => {
1169
+ mock . when (
1170
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1171
+ ) . thenCall ( ( ) => {
1172
+ resolve ( new FakeRequest ( ) ) ;
1173
+ } ) ;
1174
+ } ) ;
1175
+
1176
+ informer . start ( ) ;
1177
+ await promise ;
1178
+
1179
+ const [ , , , doneHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
1180
+
1181
+ const object = {
1182
+ kind : 'Status' ,
1183
+ apiVersion : 'v1' ,
1184
+ metadata : { } ,
1185
+ status : 'Failure' ,
1186
+ message : 'too old resource version: 12345 (1234)' ,
1187
+ reason : 'Expired' ,
1188
+ code : 410 ,
1189
+ } ;
1190
+ await watchHandler ( 'ERROR' , object , { type : 'ERROR' , object } ) ;
1191
+
1192
+ mock . verify (
1193
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1194
+ ) . thrice ( ) ;
1195
+ expect ( errorEmitted ) . to . equal ( false ) ;
1196
+ expect ( listCalls ) . to . be . equal ( 2 ) ;
1197
+ } ) ;
1198
+
1199
+ it ( 'should list if the watch errors from the last version' , async ( ) => {
1200
+ const fakeWatch = mock . mock ( Watch ) ;
1201
+ const list : V1Pod [ ] = [ ] ;
1202
+ const listObj = {
1203
+ metadata : {
1204
+ resourceVersion : '12345' ,
1205
+ } as V1ListMeta ,
1206
+ items : list ,
1207
+ } as V1NamespaceList ;
1208
+
1209
+ let listCalls = 0 ;
1210
+ const listFn : ListPromise < V1Namespace > = function ( ) : Promise < {
1211
+ response : http . IncomingMessage ;
1212
+ body : V1NamespaceList ;
1213
+ } > {
1214
+ return new Promise < { response : http . IncomingMessage ; body : V1NamespaceList } > ( ( resolve ) => {
1215
+ listCalls ++ ;
1216
+ resolve ( { response : { } as http . IncomingMessage , body : listObj } ) ;
1217
+ } ) ;
1218
+ } ;
1219
+ let promise = new Promise ( ( resolve ) => {
1220
+ mock . when (
1221
+ fakeWatch . watch ( mock . anything ( ) , mock . anything ( ) , mock . anything ( ) , mock . anything ( ) ) ,
1222
+ ) . thenCall ( ( ) => {
1223
+ resolve ( new FakeRequest ( ) ) ;
1224
+ } ) ;
1225
+ } ) ;
1226
+
1227
+ const informer = new ListWatch ( '/some/path' , mock . instance ( fakeWatch ) , listFn , false ) ;
1228
+
1229
+ informer . start ( ) ;
1230
+ await promise ;
1231
+
1232
+ const [ , , watchHandler ] = mock . capture ( fakeWatch . watch ) . last ( ) ;
1233
+ watchHandler (
1234
+ 'ADDED' ,
1235
+ {
1236
+ metadata : {
1237
+ name : 'name3' ,
1238
+ resourceVersion : '23456' ,
1239
+ } as V1ObjectMeta ,
1240
+ } as V1Namespace ,
1241
+ { type : 'ADDED' , metadata : { resourceVersion : '23456' } } ,
1159
1242
) ;
1160
1243
1161
1244
await informer . stop ( ) ;
0 commit comments