@@ -22,7 +22,7 @@ describe('AbstractCursor', function () {
22
22
before (
23
23
withClientV2 ( ( client , done ) => {
24
24
const docs = [ { a : 1 } , { a : 2 } , { a : 3 } , { a : 4 } , { a : 5 } , { a : 6 } ] ;
25
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
25
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
26
26
const tryNextColl = client . db ( ) . collection ( 'try_next' ) ;
27
27
coll . drop ( ( ) => tryNextColl . drop ( ( ) => coll . insertMany ( docs , done ) ) ) ;
28
28
} )
@@ -35,7 +35,7 @@ describe('AbstractCursor', function () {
35
35
const commands = [ ] ;
36
36
client . on ( 'commandStarted' , filterForCommands ( [ 'getMore' ] , commands ) ) ;
37
37
38
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
38
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
39
39
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
40
40
this . defer ( ( ) => cursor . close ( ) ) ;
41
41
@@ -49,14 +49,46 @@ describe('AbstractCursor', function () {
49
49
) ;
50
50
} ) ;
51
51
52
+ context ( '#readBufferedDocuments' , function ( ) {
53
+ it (
54
+ 'should support reading buffered documents' ,
55
+ withClientV2 ( function ( client , done ) {
56
+ const coll = client . db ( ) . collection ( 'abstract_cursor' ) ;
57
+ const cursor = coll . find ( { } , { batchSize : 5 } ) ;
58
+
59
+ cursor . next ( ( err , doc ) => {
60
+ expect ( err ) . to . not . exist ;
61
+ expect ( doc ) . property ( 'a' ) . to . equal ( 1 ) ;
62
+ expect ( cursor . bufferedCount ( ) ) . to . equal ( 4 ) ;
63
+
64
+ // Read the buffered Count
65
+ cursor . readBufferedDocuments ( cursor . bufferedCount ( ) ) ;
66
+
67
+ // Get the next item
68
+ cursor . next ( ( err , doc ) => {
69
+ expect ( err ) . to . not . exist ;
70
+ expect ( doc ) . to . exist ;
71
+
72
+ cursor . next ( ( err , doc ) => {
73
+ expect ( err ) . to . not . exist ;
74
+ expect ( doc ) . to . be . null ;
75
+
76
+ done ( ) ;
77
+ } ) ;
78
+ } ) ;
79
+ } ) ;
80
+ } )
81
+ ) ;
82
+ } ) ;
83
+
52
84
context ( '#close' , function ( ) {
53
85
it (
54
86
'should send a killCursors command when closed before completely iterated' ,
55
87
withClientV2 ( function ( client , done ) {
56
88
const commands = [ ] ;
57
89
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
58
90
59
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
91
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
60
92
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
61
93
cursor . next ( err => {
62
94
expect ( err ) . to . not . exist ;
@@ -75,7 +107,7 @@ describe('AbstractCursor', function () {
75
107
const commands = [ ] ;
76
108
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
77
109
78
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
110
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
79
111
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
80
112
cursor . toArray ( err => {
81
113
expect ( err ) . to . not . exist ;
@@ -95,7 +127,7 @@ describe('AbstractCursor', function () {
95
127
const commands = [ ] ;
96
128
client . on ( 'commandStarted' , filterForCommands ( [ 'killCursors' ] , commands ) ) ;
97
129
98
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
130
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
99
131
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
100
132
cursor . close ( err => {
101
133
expect ( err ) . to . not . exist ;
@@ -110,7 +142,7 @@ describe('AbstractCursor', function () {
110
142
it (
111
143
'should iterate each document in a cursor' ,
112
144
withClientV2 ( function ( client , done ) {
113
- const coll = client . db ( ) . collection ( 'find_cursor ' ) ;
145
+ const coll = client . db ( ) . collection ( 'abstract_cursor ' ) ;
114
146
const cursor = coll . find ( { } , { batchSize : 2 } ) ;
115
147
116
148
const bag = [ ] ;
0 commit comments