@@ -1848,36 +1848,44 @@ describe('Cursor', function () {
18481848 }
18491849 } ) ;
18501850
1851- it ( 'closes cursors when client is closed even if it has not been exhausted' , async function ( ) {
1852- await client
1853- . db ( )
1854- . dropCollection ( 'test_cleanup_tailable' )
1855- . catch ( ( ) => null ) ;
1851+ it (
1852+ 'closes cursors when client is closed even if it has not been exhausted' ,
1853+ { requires : { topology : '!replicaset' } } ,
1854+ async function ( ) {
1855+ await client
1856+ . db ( )
1857+ . dropCollection ( 'test_cleanup_tailable' )
1858+ . catch ( ( ) => null ) ;
18561859
1857- const collection = await client
1858- . db ( )
1859- . createCollection ( 'test_cleanup_tailable' , { capped : true , size : 1000 , max : 3 } ) ;
1860+ const collection = await client
1861+ . db ( )
1862+ . createCollection ( 'test_cleanup_tailable' , { capped : true , size : 1000 , max : 3 } ) ;
18601863
1861- // insert only 2 docs in capped coll of 3
1862- await collection . insertMany ( [ { a : 1 } , { a : 1 } ] ) ;
1864+ // insert only 2 docs in capped coll of 3
1865+ await collection . insertMany ( [ { a : 1 } , { a : 1 } ] ) ;
18631866
1864- const cursor = collection . find ( { } , { tailable : true , awaitData : true , maxAwaitTimeMS : 2000 } ) ;
1867+ const cursor = collection . find ( { } , { tailable : true , awaitData : true , maxAwaitTimeMS : 2000 } ) ;
18651868
1866- await cursor . next ( ) ;
1867- await cursor . next ( ) ;
1868- // will block for maxAwaitTimeMS (except we are closing the client)
1869- const rejectedEarlyBecauseClientClosed = cursor . next ( ) . catch ( error => error ) ;
1869+ await cursor . next ( ) ;
1870+ await cursor . next ( ) ;
18701871
1871- await client . close ( ) ;
1872- expect ( cursor ) . to . have . property ( 'closed' , true ) ;
1872+ const nextCommand = once ( client , 'commandStarted' ) ;
1873+ // will block for maxAwaitTimeMS (except we are closing the client)
1874+ const rejectedEarlyBecauseClientClosed = cursor . next ( ) . catch ( error => error ) ;
1875+
1876+ for (
1877+ let [ { commandName } ] = await nextCommand ;
1878+ commandName !== 'getMore' ;
1879+ [ { commandName } ] = await once ( client , 'commandStarted' )
1880+ ) ;
18731881
1874- const error = await rejectedEarlyBecauseClientClosed ;
1875- if ( this . configuration . topologyType === 'LoadBalanced' ) {
1882+ await client . close ( ) ;
1883+ expect ( cursor ) . to . have . property ( 'closed' , true ) ;
1884+
1885+ const error = await rejectedEarlyBecauseClientClosed ;
18761886 expect ( error ) . to . be . instanceOf ( MongoClientClosedError ) ;
1877- } else {
1878- expect ( error ) . to . be . null ;
18791887 }
1880- } ) ;
1888+ ) ;
18811889
18821890 it ( 'shouldAwaitData' , {
18831891 // Add a tag that our runner can trigger on
0 commit comments