@@ -2429,45 +2429,35 @@ describe.only('Cursor', function () {
24292429 // in this case we are setting that node needs to be higher than 0.10.X to run
24302430 metadata : { requires : { topology : [ 'single' ] , mongodb : '<7.0.0' } } ,
24312431
2432- test : function ( done ) {
2432+ test : async function ( ) {
24332433 const configuration = this . configuration ;
24342434 const client = configuration . newClient ( ) ;
2435- client . connect ( ( err , client ) => {
2436- expect ( err ) . to . not . exist ;
2437- this . defer ( ( ) => client . close ( ) ) ;
2435+ await client . connect ( ) ;
24382436
2439- const db = client . db ( configuration . db ) ;
2440- var options = { capped : true , size : 8 } ;
2441- db . createCollection (
2442- 'should_await_data_max_awaittime_ms' ,
2443- options ,
2444- function ( err , collection ) {
2445- expect ( err ) . to . not . exist ;
2437+ const db = client . db ( configuration . db ) ;
2438+ var options = { capped : true , size : 8 } ;
2439+ const collection = await db . createCollection ( 'should_await_data_max_awaittime_ms' , options ) ;
24462440
2447- collection . insert ( { a : 1 } , configuration . writeConcernMax ( ) , err => {
2448- expect ( err ) . to . not . exist ;
2449-
2450- // Create cursor with awaitData, and timeout after the period specified
2451- var cursor = collection
2452- . find ( { } )
2453- . addCursorFlag ( 'tailable' , true )
2454- . addCursorFlag ( 'awaitData' , true )
2455- . maxAwaitTimeMS ( 500 ) ;
2456-
2457- const s = new Date ( ) ;
2458- cursor . forEach (
2459- ( ) => {
2460- setTimeout ( ( ) => cursor . close ( ) , 300 ) ;
2461- } ,
2462- ( ) => {
2463- test . ok ( new Date ( ) . getTime ( ) - s . getTime ( ) >= 500 ) ;
2464- done ( ) ;
2465- }
2466- ) ;
2467- } ) ;
2468- }
2469- ) ;
2470- } ) ;
2441+ await collection . insert ( { a : 1 } , configuration . writeConcernMax ( ) ) ;
2442+
2443+ // Create cursor with awaitData, and timeout after the period specified
2444+ var cursor = collection
2445+ . find ( { } )
2446+ . addCursorFlag ( 'tailable' , true )
2447+ . addCursorFlag ( 'awaitData' , true )
2448+ . maxAwaitTimeMS ( 500 ) ;
2449+
2450+ const s = new Date ( ) ;
2451+ const err = await cursor
2452+ . forEach ( async ( ) => {
2453+ await sleep ( 300 ) ;
2454+ await cursor . close ( ) ;
2455+ } )
2456+ . catch ( e => e ) ;
2457+ test . ok ( err instanceof Error ) ;
2458+ test . ok ( new Date ( ) . getTime ( ) - s . getTime ( ) >= 500 ) ;
2459+ await cursor . close ( ) ;
2460+ await client . close ( ) ;
24712461 }
24722462 } ) ;
24732463
0 commit comments