@@ -3755,6 +3755,65 @@ describe('Cursor', function () {
3755
3755
}
3756
3756
) ;
3757
3757
3758
+ describe ( '#clone' , function ( ) {
3759
+ let client ;
3760
+ let db ;
3761
+ let collection ;
3762
+
3763
+ beforeEach ( function ( ) {
3764
+ client = this . configuration . newClient ( { w : 1 } ) ;
3765
+
3766
+ return client . connect ( ) . then ( client => {
3767
+ db = client . db ( this . configuration . db ) ;
3768
+ collection = db . collection ( 'test_coll' ) ;
3769
+ } ) ;
3770
+ } ) ;
3771
+
3772
+ afterEach ( function ( ) {
3773
+ return client . close ( ) ;
3774
+ } ) ;
3775
+
3776
+ context ( 'when executing on a find cursor' , function ( ) {
3777
+ it ( 'removes the existing session from the cloned cursor' , function ( ) {
3778
+ const docs = [ { name : 'test1' } , { name : 'test2' } ] ;
3779
+ return collection . insertMany ( docs ) . then ( ( ) => {
3780
+ const cursor = collection . find ( { } , { batchSize : 1 } ) ;
3781
+ return cursor
3782
+ . next ( )
3783
+ . then ( doc => {
3784
+ expect ( doc ) . to . exist ;
3785
+ const clonedCursor = cursor . clone ( ) ;
3786
+ expect ( clonedCursor . cursorOptions . session ) . to . not . exist ;
3787
+ expect ( clonedCursor . session ) . to . not . exist ;
3788
+ } )
3789
+ . finally ( ( ) => {
3790
+ return cursor . close ( ) ;
3791
+ } ) ;
3792
+ } ) ;
3793
+ } ) ;
3794
+ } ) ;
3795
+
3796
+ context ( 'when executing on an aggregation cursor' , function ( ) {
3797
+ it ( 'removes the existing session from the cloned cursor' , function ( ) {
3798
+ const docs = [ { name : 'test1' } , { name : 'test2' } ] ;
3799
+ return collection . insertMany ( docs ) . then ( ( ) => {
3800
+ const cursor = collection . aggregate ( [ { $match : { } } ] , { batchSize : 1 } ) ;
3801
+ return cursor
3802
+ . next ( )
3803
+ . then ( doc => {
3804
+ expect ( doc ) . to . exist ;
3805
+ const clonedCursor = cursor . clone ( ) ;
3806
+ expect ( clonedCursor . cursorOptions . session ) . to . not . exist ;
3807
+ expect ( clonedCursor . session ) . to . not . exist ;
3808
+ } )
3809
+ . finally ( ( ) => {
3810
+ return cursor . close ( ) ;
3811
+ } ) ;
3812
+ } ) ;
3813
+ } ) ;
3814
+ } ) ;
3815
+ } ) ;
3816
+
3758
3817
it ( 'should return a promise when no callback supplied to forEach method' , function ( ) {
3759
3818
const configuration = this . configuration ;
3760
3819
const client = configuration . newClient ( { w : 1 } , { maxPoolSize : 1 } ) ;
0 commit comments