@@ -1826,53 +1826,40 @@ describe.only('Cursor', function () {
18261826 requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
18271827 } ,
18281828
1829- test : function ( done ) {
1829+ test : async function ( ) {
18301830 const configuration = this . configuration ;
1831- client . connect ( ( err , client ) => {
1832- expect ( err ) . to . not . exist ;
1833- this . defer ( ( ) => client . close ( ) ) ;
1831+ await client . connect ( ) ;
18341832
1835- const db = client . db ( configuration . db ) ;
1836- db . createCollection ( 'shouldNotFailDueToStackOverflowEach' , ( err , collection ) => {
1837- expect ( err ) . to . not . exist ;
1833+ const db = client . db ( configuration . db ) ;
1834+ const collection = await db . createCollection ( 'shouldNotFailDueToStackOverflowEach' ) ;
18381835
1839- var docs = [ ] ;
1840- var total = 0 ;
1841- for ( var i = 0 ; i < 30000 ; i ++ ) docs . push ( { a : i } ) ;
1842- var allDocs = [ ] ;
1843- var left = 0 ;
1836+ var docs = [ ] ;
1837+ var total = 0 ;
1838+ for ( var i = 0 ; i < 30000 ; i ++ ) docs . push ( { a : i } ) ;
1839+ var allDocs = [ ] ;
1840+ var left = 0 ;
18441841
1845- while ( docs . length > 0 ) {
1846- allDocs . push ( docs . splice ( 0 , 1000 ) ) ;
1847- }
1848- // Get all batches we must insert
1849- left = allDocs . length ;
1850- var totalI = 0 ;
1842+ while ( docs . length > 0 ) {
1843+ allDocs . push ( docs . splice ( 0 , 1000 ) ) ;
1844+ }
1845+ // Get all batches we must insert
1846+ left = allDocs . length ;
1847+ var totalI = 0 ;
18511848
1852- // Execute inserts
1853- for ( i = 0 ; i < left ; i ++ ) {
1854- collection . insert ( allDocs . shift ( ) , configuration . writeConcernMax ( ) , function ( err , d ) {
1855- expect ( err ) . to . not . exist ;
1849+ // Execute inserts
1850+ for ( i = 0 ; i < left ; i ++ ) {
1851+ const d = await collection . insert ( allDocs . shift ( ) , configuration . writeConcernMax ( ) ) ;
18561852
1857- left = left - 1 ;
1858- totalI = totalI + d . length ;
1853+ left = left - 1 ;
1854+ totalI = totalI + d . length ;
18591855
1860- if ( left === 0 ) {
1861- collection . find ( { } ) . forEach (
1862- ( ) => {
1863- total ++ ;
1864- } ,
1865- err => {
1866- expect ( err ) . to . not . exist ;
1867- expect ( total ) . to . equal ( 30000 ) ;
1868- done ( ) ;
1869- }
1870- ) ;
1871- }
1872- } ) ;
1873- }
1874- } ) ;
1875- } ) ;
1856+ if ( left === 0 ) {
1857+ await collection . find ( { } ) . forEach ( ( ) => {
1858+ total ++ ;
1859+ } ) ;
1860+ expect ( total ) . to . equal ( 30000 ) ;
1861+ }
1862+ }
18761863 }
18771864 } ) ;
18781865
@@ -2477,8 +2464,7 @@ describe.only('Cursor', function () {
24772464 ( ) => {
24782465 setTimeout ( ( ) => cursor . close ( ) , 300 ) ;
24792466 } ,
2480- err => {
2481- console . log ( `pavel >>> err = ${ err } ` ) ;
2467+ ( ) => {
24822468 test . ok ( new Date ( ) . getTime ( ) - s . getTime ( ) >= 500 ) ;
24832469 done ( ) ;
24842470 }
@@ -2531,7 +2517,7 @@ describe.only('Cursor', function () {
25312517 requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
25322518 } ,
25332519
2534- test : function ( done ) {
2520+ test : async function ( ) {
25352521 var docs = [ ] ;
25362522
25372523 for ( var i = 0 ; i < 1 ; i ++ ) {
@@ -2540,39 +2526,23 @@ describe.only('Cursor', function () {
25402526 }
25412527
25422528 const configuration = this . configuration ;
2543- client . connect ( ( err , client ) => {
2544- expect ( err ) . to . not . exist ;
2545- this . defer ( ( ) => client . close ( ) ) ;
2529+ await client . connect ( ) ;
25462530
2547- const db = client . db ( configuration . db ) ;
2548- db . createCollection (
2549- 'shouldCorrectlyExecuteEnsureIndexWithNoCallback' ,
2550- function ( err , collection ) {
2551- expect ( err ) . to . not . exist ;
2531+ const db = client . db ( configuration . db ) ;
2532+ const collection = await db . createCollection (
2533+ 'shouldCorrectlyExecuteEnsureIndexWithNoCallback'
2534+ ) ;
25522535
2553- // ensure index of createdAt index
2554- collection . createIndex ( { createdAt : 1 } , err => {
2555- expect ( err ) . to . not . exist ;
2536+ // ensure index of createdAt index
2537+ await collection . createIndex ( { createdAt : 1 } ) ;
25562538
2557- // insert all docs
2558- collection . insert ( docs , configuration . writeConcernMax ( ) , err => {
2559- expect ( err ) . to . not . exist ;
2539+ // insert all docs
2540+ await collection . insert ( docs , configuration . writeConcernMax ( ) ) ;
25602541
2561- // Find with sort
2562- collection
2563- . find ( )
2564- . sort ( [ 'createdAt' , 'asc' ] )
2565- . toArray ( ( err , items ) => {
2566- expect ( err ) . to . not . exist ;
2542+ // Find with sort
2543+ const items = await collection . find ( ) . sort ( [ 'createdAt' , 'asc' ] ) . toArray ( ) ;
25672544
2568- test . equal ( 1 , items . length ) ;
2569- done ( ) ;
2570- } ) ;
2571- } ) ;
2572- } ) ;
2573- }
2574- ) ;
2575- } ) ;
2545+ test . equal ( 1 , items . length ) ;
25762546 }
25772547 } ) ;
25782548
@@ -2583,7 +2553,7 @@ describe.only('Cursor', function () {
25832553 requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
25842554 } ,
25852555
2586- test : function ( done ) {
2556+ test : async function ( ) {
25872557 var docs = [ ] ;
25882558
25892559 for ( var i = 0 ; i < 50 ; i ++ ) {
@@ -2592,41 +2562,22 @@ describe.only('Cursor', function () {
25922562 }
25932563
25942564 const configuration = this . configuration ;
2595- client . connect ( ( err , client ) => {
2596- expect ( err ) . to . not . exist ;
2597- this . defer ( ( ) => client . close ( ) ) ;
2565+ await client . connect ( ) ;
25982566
2599- const db = client . db ( configuration . db ) ;
2600- db . createCollection ( 'negative_batch_size_and_limit_set' , ( err , collection ) => {
2601- expect ( err ) . to . not . exist ;
2567+ const db = client . db ( configuration . db ) ;
2568+ const collection = await db . createCollection ( 'negative_batch_size_and_limit_set' ) ;
26022569
2603- // insert all docs
2604- collection . insert ( docs , configuration . writeConcernMax ( ) , err => {
2605- expect ( err ) . to . not . exist ;
2570+ // insert all docs
2571+ await collection . insert ( docs , configuration . writeConcernMax ( ) ) ;
26062572
2607- // Create a cursor for the content
2608- var cursor = collection . find ( { } ) ;
2609- cursor
2610- . limit ( 100 )
2611- . skip ( 0 )
2612- . count ( function ( err , c ) {
2613- expect ( err ) . to . not . exist ;
2614- test . equal ( 50 , c ) ;
2615-
2616- var cursor = collection . find ( { } ) ;
2617- cursor
2618- . limit ( 100 )
2619- . skip ( 0 )
2620- . toArray ( err => {
2621- expect ( err ) . to . not . exist ;
2622- test . equal ( 50 , c ) ;
2573+ // Create a cursor for the content
2574+ var cursor = collection . find ( { } ) ;
2575+ var c = await cursor . limit ( 100 ) . skip ( 0 ) . count ( ) ;
2576+ test . equal ( 50 , c ) ;
26232577
2624- done ( ) ;
2625- } ) ;
2626- } ) ;
2627- } ) ;
2628- } ) ;
2629- } ) ;
2578+ cursor = collection . find ( { } ) ;
2579+ c = ( await cursor . limit ( 100 ) . skip ( 0 ) . toArray ( ) ) . length ;
2580+ test . equal ( 50 , c ) ;
26302581 }
26312582 } ) ;
26322583
0 commit comments