@@ -1737,7 +1737,6 @@ describe('ChangeStream resumability', function () {
1737
1737
aggregateEvents = [ ] ;
1738
1738
} ) ;
1739
1739
1740
- // TODO(andymina): resumable error tests here
1741
1740
context ( 'iterator api' , function ( ) {
1742
1741
context ( '#next' , function ( ) {
1743
1742
for ( const { error, code, message } of resumableErrorCodes ) {
@@ -2140,7 +2139,7 @@ describe('ChangeStream resumability', function () {
2140
2139
} ) ;
2141
2140
} ) ;
2142
2141
2143
- context ( '#asyncIterator' , function ( ) {
2142
+ context . only ( '#asyncIterator' , function ( ) {
2144
2143
for ( const { error, code, message } of resumableErrorCodes ) {
2145
2144
it (
2146
2145
`resumes on error code ${ code } (${ error } )` ,
@@ -2241,13 +2240,51 @@ describe('ChangeStream resumability', function () {
2241
2240
}
2242
2241
) ;
2243
2242
2243
+ it (
2244
+ 'maintains change stream options on resume' ,
2245
+ { requires : { topology : '!single' , mongodb : '>=4.2' } } ,
2246
+ async function ( ) {
2247
+ changeStream = collection . watch ( [ ] , changeStreamResumeOptions ) ;
2248
+ await initIteratorMode ( changeStream ) ;
2249
+
2250
+ await client . db ( 'admin' ) . command ( {
2251
+ configureFailPoint : is4_2Server ( this . configuration . version )
2252
+ ? 'failCommand'
2253
+ : 'failGetMoreAfterCursorCheckout' ,
2254
+ mode : { times : 1 } ,
2255
+ data : {
2256
+ failCommands : [ 'getMore' ] ,
2257
+ errorCode : resumableErrorCodes [ 0 ] . code ,
2258
+ errmsg : resumableErrorCodes [ 0 ] . message
2259
+ }
2260
+ } as FailPoint ) ;
2261
+
2262
+ expect ( changeStream . cursor )
2263
+ . to . have . property ( 'options' )
2264
+ . that . containSubset ( changeStreamResumeOptions ) ;
2265
+
2266
+ await collection . insertOne ( { city : 'New York City' } ) ;
2267
+
2268
+ let total_changes = 0 ;
2269
+ for await ( const change of changeStream ) {
2270
+ total_changes ++ ;
2271
+ if ( total_changes === 1 ) {
2272
+ changeStream . close ( ) ;
2273
+ }
2274
+ }
2275
+
2276
+ expect ( changeStream . cursor )
2277
+ . to . have . property ( 'options' )
2278
+ . that . containSubset ( changeStreamResumeOptions ) ;
2279
+ }
2280
+ ) ;
2281
+
2244
2282
context ( 'when the error is not a resumable error' , function ( ) {
2245
2283
it (
2246
2284
'does not resume' ,
2247
2285
{ requires : { topology : '!single' , mongodb : '>=4.2' } } ,
2248
2286
async function ( ) {
2249
2287
changeStream = collection . watch ( [ ] ) ;
2250
- await initIteratorMode ( changeStream ) ;
2251
2288
2252
2289
const unresumableErrorCode = 1000 ;
2253
2290
await client . db ( 'admin' ) . command ( {
@@ -2261,15 +2298,20 @@ describe('ChangeStream resumability', function () {
2261
2298
}
2262
2299
} as FailPoint ) ;
2263
2300
2264
- await collection . insertOne ( { city : 'New York City' } ) ;
2301
+ await initIteratorMode ( changeStream ) ;
2265
2302
2303
+ await collection . insertOne ( { city : 'New York City' } ) ;
2266
2304
try {
2267
2305
for await ( const change of changeStream ) {
2268
- // should not run
2306
+ // DOESN'T REACH
2307
+ expect . fail ( 'Change stream produced changes on an unresumable error' ) ;
2269
2308
}
2270
2309
} catch ( error ) {
2271
2310
expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
2311
+ expect ( aggregateEvents ) . to . have . lengthOf ( 1 ) ;
2272
2312
}
2313
+ // fails here
2314
+ expect . fail ( 'Change stream did not throw unresumable error' ) ;
2273
2315
}
2274
2316
) ;
2275
2317
} ) ;
0 commit comments