@@ -1848,36 +1848,44 @@ describe('Cursor', function () {
1848
1848
}
1849
1849
} ) ;
1850
1850
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 ) ;
1856
1859
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 } ) ;
1860
1863
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 } ] ) ;
1863
1866
1864
- const cursor = collection . find ( { } , { tailable : true , awaitData : true , maxAwaitTimeMS : 2000 } ) ;
1867
+ const cursor = collection . find ( { } , { tailable : true , awaitData : true , maxAwaitTimeMS : 2000 } ) ;
1865
1868
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 ( ) ;
1870
1871
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
+ ) ;
1873
1881
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 ;
1876
1886
expect ( error ) . to . be . instanceOf ( MongoClientClosedError ) ;
1877
- } else {
1878
- expect ( error ) . to . be . null ;
1879
1887
}
1880
- } ) ;
1888
+ ) ;
1881
1889
1882
1890
it ( 'shouldAwaitData' , {
1883
1891
// Add a tag that our runner can trigger on
0 commit comments