@@ -73,6 +73,7 @@ describe('Change Streams', function () {
73
73
} ) ;
74
74
75
75
afterEach ( async ( ) => {
76
+ sinon . restore ( ) ;
76
77
await changeStream . close ( ) ;
77
78
await client . close ( ) ;
78
79
await mock . cleanup ( ) ;
@@ -952,7 +953,7 @@ describe('Change Streams', function () {
952
953
'This test only worked because of timing, changeStream.close does not remove the change listener' ;
953
954
} ) ;
954
955
955
- context ( 'iterator api' , function ( ) {
956
+ describe ( 'iterator api' , function ( ) {
956
957
describe ( '#tryNext()' , function ( ) {
957
958
it ( 'should return null on single iteration of empty cursor' , {
958
959
metadata : { requires : { topology : 'replicaset' } } ,
@@ -998,8 +999,6 @@ describe('Change Streams', function () {
998
999
const { fullDocument } = change . value ;
999
1000
expect ( fullDocument . city ) . to . equal ( doc . city ) ;
1000
1001
}
1001
-
1002
- changeStream . close ( ) ;
1003
1002
}
1004
1003
) ;
1005
1004
@@ -1009,18 +1008,12 @@ describe('Change Streams', function () {
1009
1008
async function ( ) {
1010
1009
changeStream = collection . watch ( [ ] ) ;
1011
1010
await initIteratorMode ( changeStream ) ;
1011
+ const changeStreamIterator = changeStream [ Symbol . asyncIterator ] ( ) ;
1012
1012
1013
1013
const docs = [ { city : 'New York City' } , { city : 'Seattle' } , { city : 'Boston' } ] ;
1014
1014
await collection . insertMany ( docs ) ;
1015
1015
1016
- const changeStreamAsyncIteratorHelper = async function ( changeStream : ChangeStream ) {
1017
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1018
- for await ( const change of changeStream ) {
1019
- return ;
1020
- }
1021
- } ;
1022
-
1023
- await changeStreamAsyncIteratorHelper ( changeStream ) ;
1016
+ await changeStreamIterator . return ( ) ;
1024
1017
expect ( changeStream . closed ) . to . be . true ;
1025
1018
expect ( changeStream . cursor . closed ) . to . be . true ;
1026
1019
}
@@ -1114,6 +1107,24 @@ describe('Change Streams', function () {
1114
1107
}
1115
1108
}
1116
1109
) ;
1110
+
1111
+ it (
1112
+ 'ignores errors thrown from close' ,
1113
+ { requires : { topology : '!single' } } ,
1114
+ async function ( ) {
1115
+ changeStream = collection . watch ( [ ] ) ;
1116
+ await initIteratorMode ( changeStream ) ;
1117
+ const changeStreamIterator = changeStream [ Symbol . asyncIterator ] ( ) ;
1118
+
1119
+ sinon . stub ( changeStream . cursor , 'close' ) . throws ( new MongoAPIError ( 'testing' ) ) ;
1120
+
1121
+ try {
1122
+ await changeStreamIterator . return ( ) ;
1123
+ } catch ( error ) {
1124
+ expect . fail ( 'Async iterator threw an error on close' ) ;
1125
+ }
1126
+ }
1127
+ ) ;
1117
1128
} ) ;
1118
1129
} ) ;
1119
1130
@@ -2362,8 +2373,6 @@ describe('ChangeStream resumability', function () {
2362
2373
await changeStreamIterator . next ( ) ;
2363
2374
2364
2375
expect ( aggregateEvents ) . to . have . lengthOf ( 2 ) ;
2365
-
2366
- changeStream . close ( ) ;
2367
2376
}
2368
2377
) ;
2369
2378
}
@@ -2397,8 +2406,6 @@ describe('ChangeStream resumability', function () {
2397
2406
await changeStreamIterator . next ( ) ;
2398
2407
2399
2408
expect ( aggregateEvents ) . to . have . lengthOf ( 2 ) ;
2400
-
2401
- changeStream . close ( ) ;
2402
2409
}
2403
2410
) ;
2404
2411
}
@@ -2467,8 +2474,6 @@ describe('ChangeStream resumability', function () {
2467
2474
expect ( error ) . to . be . instanceOf ( MongoServerError ) ;
2468
2475
expect ( aggregateEvents ) . to . have . lengthOf ( 1 ) ;
2469
2476
}
2470
-
2471
- changeStream . close ( ) ;
2472
2477
}
2473
2478
) ;
2474
2479
} ) ;
0 commit comments