1
- use bson:: doc;
2
-
3
1
use crate :: {
4
2
client:: {
5
3
auth:: { oidc, AuthMechanism , Credential } ,
@@ -107,7 +105,7 @@ async fn machine_1_1_callback_is_called() -> anyhow::Result<()> {
107
105
client
108
106
. database ( "test" )
109
107
. collection :: < Document > ( "test" )
110
- . find_one ( None , None )
108
+ . find_one ( doc ! { } )
111
109
. await ?;
112
110
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
113
111
Ok ( ( ) )
@@ -146,7 +144,7 @@ async fn machine_1_2_callback_is_called_only_once_for_multiple_connections() ->
146
144
client
147
145
. database ( "test" )
148
146
. collection :: < Document > ( "test" )
149
- . find_one ( None , None )
147
+ . find_one ( doc ! { } )
150
148
. await
151
149
. unwrap ( ) ;
152
150
}
@@ -227,7 +225,7 @@ async fn machine_2_3_oidc_callback_return_missing_data() -> anyhow::Result<()> {
227
225
let res = client
228
226
. database ( "test" )
229
227
. collection :: < Document > ( "test" )
230
- . find_one ( None , None )
228
+ . find_one ( doc ! { } )
231
229
. await ;
232
230
233
231
assert ! ( res. is_err( ) ) ;
@@ -270,7 +268,7 @@ async fn machine_2_4_invalid_client_configuration_with_callback() -> anyhow::Res
270
268
let res = client
271
269
. database ( "test" )
272
270
. collection :: < Document > ( "test" )
273
- . find_one ( None , None )
271
+ . find_one ( doc ! { } )
274
272
. await ;
275
273
276
274
assert ! ( res. is_err( ) ) ;
@@ -323,7 +321,7 @@ async fn machine_3_1_failure_with_cached_tokens_fetch_a_new_token_and_retry_auth
323
321
client
324
322
. database ( "test" )
325
323
. collection :: < Document > ( "test" )
326
- . find_one ( None , None )
324
+ . find_one ( doc ! { } )
327
325
. await ?;
328
326
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
329
327
Ok ( ( ) )
@@ -357,7 +355,7 @@ async fn machine_3_2_auth_failures_without_cached_tokens_returns_an_error() -> a
357
355
let res = client
358
356
. database ( "test" )
359
357
. collection :: < Document > ( "test" )
360
- . find_one ( None , None )
358
+ . find_one ( doc ! { } )
361
359
. await ;
362
360
363
361
assert ! ( res. is_err( ) ) ;
@@ -409,7 +407,7 @@ async fn machine_4_reauthentication() -> anyhow::Result<()> {
409
407
client
410
408
. database ( "test" )
411
409
. collection :: < Document > ( "test" )
412
- . find_one ( None , None )
410
+ . find_one ( doc ! { } )
413
411
. await ?;
414
412
assert_eq ! ( 2 , * ( * call_count) . lock( ) . await ) ;
415
413
Ok ( ( ) )
@@ -479,7 +477,7 @@ async fn human_1_2_single_principal_explicit_username() -> anyhow::Result<()> {
479
477
client
480
478
. database ( "test" )
481
479
. collection :: < Document > ( "test" )
482
- . find_one ( None , None )
480
+ . find_one ( doc ! { } )
483
481
. await ?;
484
482
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
485
483
Ok ( ( ) )
@@ -514,7 +512,7 @@ async fn human_1_3_multiple_principal_user_1() -> anyhow::Result<()> {
514
512
client
515
513
. database ( "test" )
516
514
. collection :: < Document > ( "test" )
517
- . find_one ( None , None )
515
+ . find_one ( doc ! { } )
518
516
. await ?;
519
517
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
520
518
Ok ( ( ) )
@@ -549,7 +547,7 @@ async fn human_1_4_multiple_principal_user_2() -> anyhow::Result<()> {
549
547
client
550
548
. database ( "test" )
551
549
. collection :: < Document > ( "test" )
552
- . find_one ( None , None )
550
+ . find_one ( doc ! { } )
553
551
. await ?;
554
552
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
555
553
Ok ( ( ) )
@@ -583,7 +581,7 @@ async fn human_1_5_multiple_principal_no_user() -> anyhow::Result<()> {
583
581
let res = client
584
582
. database ( "test" )
585
583
. collection :: < Document > ( "test" )
586
- . find_one ( None , None )
584
+ . find_one ( doc ! { } )
587
585
. await ;
588
586
589
587
assert ! ( res. is_err( ) ) ;
@@ -628,7 +626,7 @@ async fn human_1_6_allowed_hosts_blocked() -> anyhow::Result<()> {
628
626
let res = client
629
627
. database ( "test" )
630
628
. collection :: < Document > ( "test" )
631
- . find_one ( None , None )
629
+ . find_one ( doc ! { } )
632
630
. await ;
633
631
634
632
assert ! ( res. is_err( ) ) ;
@@ -669,7 +667,7 @@ async fn human_1_6_allowed_hosts_blocked() -> anyhow::Result<()> {
669
667
let res = client
670
668
. database ( "test" )
671
669
. collection :: < Document > ( "test" )
672
- . find_one ( None , None )
670
+ . find_one ( doc ! { } )
673
671
. await ;
674
672
675
673
assert ! ( res. is_err( ) ) ;
@@ -716,7 +714,7 @@ async fn human_2_1_valid_callback_inputs() -> anyhow::Result<()> {
716
714
client
717
715
. database ( "test" )
718
716
. collection :: < Document > ( "test" )
719
- . find_one ( None , None )
717
+ . find_one ( doc ! { } )
720
718
. await ?;
721
719
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
722
720
Ok ( ( ) )
@@ -750,7 +748,7 @@ async fn human_2_2_callback_returns_missing_data() -> anyhow::Result<()> {
750
748
let res = client
751
749
. database ( "test" )
752
750
. collection :: < Document > ( "test" )
753
- . find_one ( None , None )
751
+ . find_one ( doc ! { } )
754
752
. await ;
755
753
756
754
assert ! ( res. is_err( ) ) ;
@@ -825,7 +823,7 @@ async fn human_3_1_uses_speculative_authentication_if_there_is_a_cached_token()
825
823
client
826
824
. database ( "test" )
827
825
. collection :: < Document > ( "test" )
828
- . find_one ( None , None )
826
+ . find_one ( doc ! { } )
829
827
. await ?;
830
828
831
829
// the callback should not have been called at all
@@ -874,7 +872,7 @@ async fn human_3_2_does_not_use_speculative_authentication_if_there_is_no_cached
874
872
let res = client
875
873
. database ( "test" )
876
874
. collection :: < Document > ( "test" )
877
- . find_one ( None , None )
875
+ . find_one ( doc ! { } )
878
876
. await ;
879
877
880
878
assert ! ( res. is_err( ) ) ;
@@ -891,13 +889,8 @@ async fn human_3_2_does_not_use_speculative_authentication_if_there_is_no_cached
891
889
async fn human_4_1_succeeds ( ) -> anyhow:: Result < ( ) > {
892
890
get_env_or_skip ! ( "OIDC" ) ;
893
891
use crate :: {
894
- event:: command:: {
895
- CommandEvent ,
896
- CommandFailedEvent ,
897
- CommandStartedEvent ,
898
- CommandSucceededEvent ,
899
- } ,
900
- test:: { Event , EventHandler } ,
892
+ event:: command:: CommandEvent ,
893
+ test:: { util:: event_buffer:: EventBuffer , Event } ,
901
894
} ;
902
895
903
896
let admin_client = admin_client ! ( ) ;
@@ -924,15 +917,14 @@ async fn human_4_1_succeeds() -> anyhow::Result<()> {
924
917
. build ( )
925
918
. into ( ) ;
926
919
927
- let handler = Arc :: new ( EventHandler :: new ( ) ) ;
928
- let mut events = handler. subscribe ( ) ;
929
- opts. command_event_handler = Some ( handler. clone ( ) . into ( ) ) ;
920
+ let buffer = EventBuffer :: new ( ) ;
921
+ opts. command_event_handler = Some ( buffer. handler ( ) ) ;
930
922
let client = Client :: with_options ( opts) ?;
931
923
932
924
client
933
925
. database ( "test" )
934
926
. collection :: < Document > ( "test" )
935
- . find_one ( None , None )
927
+ . find_one ( doc ! { } )
936
928
. await ?;
937
929
938
930
// Now set a failpoint for find with 391 error code
@@ -947,67 +939,47 @@ async fn human_4_1_succeeds() -> anyhow::Result<()> {
947
939
client
948
940
. database ( "test" )
949
941
. collection :: < Document > ( "test" )
950
- . find_one ( None , None )
942
+ . find_one ( doc ! { } )
951
943
. await ?;
952
944
953
945
assert_eq ! ( 2 , * ( * call_count) . lock( ) . await ) ;
954
- let events = events
955
- . collect_events ( Duration :: from_secs ( 1 ) , |e| {
956
- if let Some ( e) = e. as_command_event ( ) {
957
- e. command_name ( ) == "find"
958
- } else {
959
- false
960
- }
961
- } )
962
- . await ;
963
- // assert the first command is find
946
+ let find_events = buffer. filter_map ( |e : & Event | match e. as_command_event ( ) {
947
+ Some ( command_event) if command_event. command_name ( ) == "find" => {
948
+ Some ( command_event. clone ( ) )
949
+ }
950
+ _ => None ,
951
+ } ) ;
952
+ // assert the first find started
964
953
assert ! ( matches!(
965
- events. first( ) . unwrap( ) ,
966
- Event :: Command ( CommandEvent :: Started ( CommandStartedEvent {
967
- command_name,
968
- ..
969
- } ) ) if command_name. as_str( ) == "find"
954
+ find_events. first( ) . unwrap( ) ,
955
+ CommandEvent :: Started ( _)
970
956
) ) ;
971
- // assert the first command is find and succeeded
957
+ // assert the first find succeeded
972
958
assert ! ( matches!(
973
- events. get( 1 ) . unwrap( ) ,
974
- Event :: Command ( CommandEvent :: Succeeded ( CommandSucceededEvent {
975
- command_name,
976
- ..
977
- } ) ) if command_name. as_str( ) == "find"
959
+ find_events. get( 1 ) . unwrap( ) ,
960
+ CommandEvent :: Succeeded ( _)
978
961
) ) ;
979
- // assert the second command is find
962
+ // assert the second find started
980
963
assert ! ( matches!(
981
- events. get( 2 ) . unwrap( ) ,
982
- Event :: Command ( CommandEvent :: Started ( CommandStartedEvent {
983
- command_name,
984
- ..
985
- } ) ) if command_name. as_str( ) == "find"
964
+ find_events. get( 2 ) . unwrap( ) ,
965
+ CommandEvent :: Started ( _)
986
966
) ) ;
987
- // assert the second command is find and failed
967
+ // assert the second find failed
988
968
assert ! ( matches!(
989
- events. get( 3 ) . unwrap( ) ,
990
- Event :: Command ( CommandEvent :: Failed ( CommandFailedEvent {
991
- command_name,
992
- ..
993
- } ) ) if command_name. as_str( ) == "find"
969
+ find_events. get( 3 ) . unwrap( ) ,
970
+ CommandEvent :: Failed ( _)
994
971
) ) ;
995
- // assert the third command is find
972
+ // assert the first find started
996
973
assert ! ( matches!(
997
- events. get( 4 ) . unwrap( ) ,
998
- Event :: Command ( CommandEvent :: Started ( CommandStartedEvent {
999
- command_name,
1000
- ..
1001
- } ) ) if command_name. as_str( ) == "find"
974
+ find_events. get( 4 ) . unwrap( ) ,
975
+ CommandEvent :: Started ( _)
1002
976
) ) ;
1003
- // assert the third command is find and succeeded
977
+ // assert the third find succeeded
1004
978
assert ! ( matches!(
1005
- events. get( 5 ) . unwrap( ) ,
1006
- Event :: Command ( CommandEvent :: Succeeded ( CommandSucceededEvent {
1007
- command_name,
1008
- ..
1009
- } ) ) if command_name. as_str( ) == "find"
979
+ find_events. get( 5 ) . unwrap( ) ,
980
+ CommandEvent :: Succeeded ( _)
1010
981
) ) ;
982
+
1011
983
Ok ( ( ) )
1012
984
}
1013
985
@@ -1042,7 +1014,7 @@ async fn human_4_2_succeeds_no_refresh() -> anyhow::Result<()> {
1042
1014
client
1043
1015
. database ( "test" )
1044
1016
. collection :: < Document > ( "test" )
1045
- . find_one ( None , None )
1017
+ . find_one ( doc ! { } )
1046
1018
. await ?;
1047
1019
1048
1020
// Now set a failpoint for find with 391 error code
@@ -1057,7 +1029,7 @@ async fn human_4_2_succeeds_no_refresh() -> anyhow::Result<()> {
1057
1029
client
1058
1030
. database ( "test" )
1059
1031
. collection :: < Document > ( "test" )
1060
- . find_one ( None , None )
1032
+ . find_one ( doc ! { } )
1061
1033
. await ?;
1062
1034
1063
1035
assert_eq ! ( 2 , * ( * call_count) . lock( ) . await ) ;
@@ -1095,7 +1067,7 @@ async fn human_4_3_succeeds_after_refresh_fails() -> anyhow::Result<()> {
1095
1067
client
1096
1068
. database ( "test" )
1097
1069
. collection :: < Document > ( "test" )
1098
- . find_one ( None , None )
1070
+ . find_one ( doc ! { } )
1099
1071
. await ?;
1100
1072
1101
1073
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
@@ -1112,7 +1084,7 @@ async fn human_4_3_succeeds_after_refresh_fails() -> anyhow::Result<()> {
1112
1084
client
1113
1085
. database ( "test" )
1114
1086
. collection :: < Document > ( "test" )
1115
- . find_one ( None , None )
1087
+ . find_one ( doc ! { } )
1116
1088
. await ?;
1117
1089
1118
1090
assert_eq ! ( 3 , * ( * call_count) . lock( ) . await ) ;
@@ -1150,7 +1122,7 @@ async fn human_4_4_fails() -> anyhow::Result<()> {
1150
1122
client
1151
1123
. database ( "test" )
1152
1124
. collection :: < Document > ( "test" )
1153
- . find_one ( None , None )
1125
+ . find_one ( doc ! { } )
1154
1126
. await ?;
1155
1127
1156
1128
assert_eq ! ( 1 , * ( * call_count) . lock( ) . await ) ;
@@ -1167,7 +1139,7 @@ async fn human_4_4_fails() -> anyhow::Result<()> {
1167
1139
let res = client
1168
1140
. database ( "test" )
1169
1141
. collection :: < Document > ( "test" )
1170
- . find_one ( None , None )
1142
+ . find_one ( doc ! { } )
1171
1143
. await ;
1172
1144
1173
1145
assert ! ( res. is_err( ) ) ;
@@ -1229,7 +1201,7 @@ async fn human_4_5_refresh_token_flow() -> anyhow::Result<()> {
1229
1201
client
1230
1202
. database ( "test" )
1231
1203
. collection :: < Document > ( "test" )
1232
- . find_one ( None , None )
1204
+ . find_one ( doc ! { } )
1233
1205
. await ?;
1234
1206
1235
1207
// the callback should have been called once
0 commit comments