@@ -466,3 +466,56 @@ async fn empty_insert() {
466
466
e => panic ! ( "expected argument error, got {:?}" , e) ,
467
467
} ;
468
468
}
469
+
470
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
471
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
472
+ async fn find_allow_disk_use ( ) {
473
+ let find_opts = FindOptions :: builder ( ) . allow_disk_use ( true ) . build ( ) ;
474
+ allow_disk_use_test ( find_opts, Some ( true ) ) . await ;
475
+ }
476
+
477
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
478
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
479
+ async fn find_do_not_allow_disk_use ( ) {
480
+ let find_opts = FindOptions :: builder ( ) . allow_disk_use ( false ) . build ( ) ;
481
+ allow_disk_use_test ( find_opts, Some ( false ) ) . await ;
482
+ }
483
+
484
+ #[ cfg_attr( feature = "tokio-runtime" , tokio:: test) ]
485
+ #[ cfg_attr( feature = "async-std-runtime" , async_std:: test) ]
486
+ async fn find_allow_disk_use_not_specified ( ) {
487
+ let find_opts = FindOptions :: builder ( ) . build ( ) ;
488
+ allow_disk_use_test ( find_opts, None ) . await ;
489
+ }
490
+
491
+ #[ function_name:: named]
492
+ async fn allow_disk_use_test ( options : FindOptions , expected_value : Option < bool > ) {
493
+ let _guard = LOCK . run_concurrently ( ) . await ;
494
+
495
+ let event_client = EventClient :: new ( ) . await ;
496
+ if event_client. server_version_lt ( 4 , 3 ) {
497
+ return ;
498
+ }
499
+ let coll = event_client
500
+ . database ( function_name ! ( ) )
501
+ . collection ( function_name ! ( ) ) ;
502
+ coll. find ( None , options) . await . unwrap ( ) ;
503
+
504
+ let events = event_client. command_events . read ( ) . unwrap ( ) ;
505
+ let mut iter = events. iter ( ) . filter ( |event| match event {
506
+ CommandEvent :: CommandStartedEvent ( CommandStartedEvent { command_name, .. } ) => {
507
+ command_name == "find"
508
+ }
509
+ _ => false ,
510
+ } ) ;
511
+
512
+ let event = iter. next ( ) . unwrap ( ) ;
513
+ let allow_disk_use = match event {
514
+ CommandEvent :: CommandStartedEvent ( CommandStartedEvent { command, .. } ) => {
515
+ command. get_bool ( "allowDiskUse" ) . ok ( )
516
+ }
517
+ _ => None ,
518
+ } ;
519
+ assert_eq ! ( allow_disk_use, expected_value) ;
520
+ assert_eq ! ( iter. count( ) , 0 ) ;
521
+ }
0 commit comments