File tree Expand file tree Collapse file tree 4 files changed +51
-4
lines changed Expand file tree Collapse file tree 4 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,16 @@ pub mod event;
3
3
pub ( crate ) mod options;
4
4
pub mod session;
5
5
6
+ #[ cfg( test) ]
7
+ use std:: collections:: VecDeque ;
6
8
use std:: {
7
9
future:: Future ,
8
10
pin:: Pin ,
9
11
task:: { Context , Poll } ,
10
12
} ;
11
13
14
+ #[ cfg( test) ]
15
+ use bson:: RawDocumentBuf ;
12
16
use bson:: { Document , Timestamp } ;
13
17
use derivative:: Derivative ;
14
18
use futures_core:: { future:: BoxFuture , Stream } ;
@@ -167,6 +171,11 @@ where
167
171
pub ( crate ) fn set_kill_watcher ( & mut self , tx : oneshot:: Sender < ( ) > ) {
168
172
self . cursor . set_kill_watcher ( tx) ;
169
173
}
174
+
175
+ #[ cfg( test) ]
176
+ pub ( crate ) fn current_batch ( & self ) -> & VecDeque < RawDocumentBuf > {
177
+ self . cursor . current_batch ( )
178
+ }
170
179
}
171
180
172
181
/// Arguments passed to a `watch` method, captured to allow resume.
Original file line number Diff line number Diff line change 87
87
self . state ( ) . buffer . current ( )
88
88
}
89
89
90
+ #[ cfg( test) ]
91
+ pub ( super ) fn current_batch ( & self ) -> & VecDeque < RawDocumentBuf > {
92
+ self . state ( ) . buffer . as_ref ( )
93
+ }
94
+
90
95
fn state_mut ( & mut self ) -> & mut CursorState {
91
96
self . state . as_mut ( ) . unwrap ( )
92
97
}
@@ -531,3 +536,9 @@ impl CursorBuffer {
531
536
self . docs . front ( ) . map ( |d| d. as_ref ( ) )
532
537
}
533
538
}
539
+
540
+ impl AsRef < VecDeque < RawDocumentBuf > > for CursorBuffer {
541
+ fn as_ref ( & self ) -> & VecDeque < RawDocumentBuf > {
542
+ & self . docs
543
+ }
544
+ }
Original file line number Diff line number Diff line change 1
1
mod common;
2
2
pub ( crate ) mod session;
3
3
4
+ #[ cfg( test) ]
5
+ use std:: collections:: VecDeque ;
4
6
use std:: {
5
7
pin:: Pin ,
6
8
task:: { Context , Poll } ,
7
9
} ;
8
10
9
11
use bson:: RawDocument ;
12
+
13
+ #[ cfg( test) ]
14
+ use bson:: RawDocumentBuf ;
10
15
use futures_core:: { future:: BoxFuture , Stream } ;
11
16
use serde:: { de:: DeserializeOwned , Deserialize } ;
12
17
#[ cfg( test) ]
@@ -269,6 +274,11 @@ impl<T> Cursor<T> {
269
274
) ;
270
275
self . kill_watcher = Some ( tx) ;
271
276
}
277
+
278
+ #[ cfg( test) ]
279
+ pub ( crate ) fn current_batch ( & self ) -> & VecDeque < RawDocumentBuf > {
280
+ self . wrapped_cursor . as_ref ( ) . unwrap ( ) . current_batch ( )
281
+ }
272
282
}
273
283
274
284
impl < T > CursorStream for Cursor < T >
Original file line number Diff line number Diff line change @@ -455,11 +455,28 @@ async fn batch_mid_resume_token() -> Result<()> {
455
455
None => return Ok ( ( ) ) ,
456
456
} ;
457
457
458
- coll. insert_many ( ( 0 ..2 ) . map ( |i| doc ! { "_id" : i as i32 } ) , None )
459
- . await ?;
458
+ // This loop gets the stream to a point where it has been iterated up to but not including
459
+ // the last event in its batch.
460
+ let mut event_id = None ;
461
+ loop {
462
+ match stream. next_if_any ( ) . await ? {
463
+ Some ( event) => {
464
+ event_id = Some ( event. id ) ;
465
+ }
466
+ // If we're out of events, make some more.
467
+ None => {
468
+ coll. insert_many ( ( 0 ..3 ) . map ( |_| doc ! { } ) , None ) . await ?;
469
+ }
470
+ } ;
471
+
472
+ // if after iterating the stream last time there's one document left,
473
+ // then we're done here and can continue to the assertions.
474
+ if stream. current_batch ( ) . len ( ) == 1 {
475
+ break ;
476
+ }
477
+ }
460
478
461
- let mid_id = stream. next ( ) . await . transpose ( ) ?. unwrap ( ) . id ;
462
- assert_eq ! ( stream. resume_token( ) , Some ( mid_id) ) ;
479
+ assert_eq ! ( stream. resume_token( ) . unwrap( ) , event_id. unwrap( ) ) ;
463
480
464
481
Ok ( ( ) )
465
482
}
You can’t perform that action at this time.
0 commit comments