@@ -5,6 +5,8 @@ use std::{future::Future, sync::Arc, time::Duration};
5
5
use bson:: Document ;
6
6
use futures:: stream:: StreamExt ;
7
7
8
+ #[ allow( deprecated) ]
9
+ use crate :: test:: EventClient ;
8
10
use crate :: {
9
11
bson:: { doc, Bson } ,
10
12
coll:: options:: CountOptions ,
@@ -13,7 +15,13 @@ use crate::{
13
15
options:: { FindOptions , ReadConcern , ReadPreference , WriteConcern } ,
14
16
sdam:: ServerInfo ,
15
17
selection_criteria:: SelectionCriteria ,
16
- test:: { get_client_options, log_uncaptured, Event , EventClient , EventHandler , TestClient } ,
18
+ test:: {
19
+ get_client_options,
20
+ log_uncaptured,
21
+ util:: event_buffer:: EventBuffer ,
22
+ Event ,
23
+ TestClient ,
24
+ } ,
17
25
Client ,
18
26
Collection ,
19
27
} ;
@@ -231,13 +239,14 @@ async fn cluster_time_in_commands() {
231
239
async fn cluster_time_test < F , G , R > (
232
240
command_name : & str ,
233
241
client : & Client ,
234
- event_handler : & EventHandler ,
242
+ event_buffer : & EventBuffer ,
235
243
operation : F ,
236
244
) where
237
245
F : Fn ( Client ) -> G ,
238
246
G : Future < Output = Result < R > > ,
239
247
{
240
- let mut subscriber = event_handler. subscribe ( ) ;
248
+ #[ allow( deprecated) ]
249
+ let mut subscriber = event_buffer. subscribe ( ) ;
241
250
242
251
operation ( client. clone ( ) )
243
252
. await
@@ -284,11 +293,11 @@ async fn cluster_time_in_commands() {
284
293
) ;
285
294
}
286
295
287
- let handler = Arc :: new ( EventHandler :: new ( ) ) ;
296
+ let buffer = EventBuffer :: new ( ) ;
288
297
let mut options = get_client_options ( ) . await . clone ( ) ;
289
298
options. heartbeat_freq = Some ( Duration :: from_secs ( 1000 ) ) ;
290
- options. command_event_handler = Some ( handler . clone ( ) . into ( ) ) ;
291
- options. sdam_event_handler = Some ( handler . clone ( ) . into ( ) ) ;
299
+ options. command_event_handler = Some ( buffer . handler ( ) ) ;
300
+ options. sdam_event_handler = Some ( buffer . handler ( ) ) ;
292
301
293
302
// Ensure we only connect to one server so the monitor checks from other servers
294
303
// don't affect the TopologyDescription's clusterTime value between commands.
@@ -304,7 +313,8 @@ async fn cluster_time_in_commands() {
304
313
}
305
314
}
306
315
307
- let mut subscriber = handler. subscribe ( ) ;
316
+ #[ allow( deprecated) ]
317
+ let mut subscriber = buffer. subscribe ( ) ;
308
318
309
319
let client = Client :: with_options ( options) . unwrap ( ) ;
310
320
@@ -328,29 +338,24 @@ async fn cluster_time_in_commands() {
328
338
. await
329
339
. unwrap ( ) ;
330
340
331
- cluster_time_test ( "ping" , & client, handler . as_ref ( ) , |client| async move {
341
+ cluster_time_test ( "ping" , & client, & buffer , |client| async move {
332
342
client
333
343
. database ( function_name ! ( ) )
334
344
. run_command ( doc ! { "ping" : 1 } )
335
345
. await
336
346
} )
337
347
. await ;
338
348
339
- cluster_time_test (
340
- "aggregate" ,
341
- & client,
342
- handler. as_ref ( ) ,
343
- |client| async move {
344
- client
345
- . database ( function_name ! ( ) )
346
- . collection :: < Document > ( function_name ! ( ) )
347
- . aggregate ( vec ! [ doc! { "$match" : { "x" : 1 } } ] )
348
- . await
349
- } ,
350
- )
349
+ cluster_time_test ( "aggregate" , & client, & buffer, |client| async move {
350
+ client
351
+ . database ( function_name ! ( ) )
352
+ . collection :: < Document > ( function_name ! ( ) )
353
+ . aggregate ( vec ! [ doc! { "$match" : { "x" : 1 } } ] )
354
+ . await
355
+ } )
351
356
. await ;
352
357
353
- cluster_time_test ( "find" , & client, handler . as_ref ( ) , |client| async move {
358
+ cluster_time_test ( "find" , & client, & buffer , |client| async move {
354
359
client
355
360
. database ( function_name ! ( ) )
356
361
. collection :: < Document > ( function_name ! ( ) )
@@ -359,7 +364,7 @@ async fn cluster_time_in_commands() {
359
364
} )
360
365
. await ;
361
366
362
- cluster_time_test ( "insert" , & client, handler . as_ref ( ) , |client| async move {
367
+ cluster_time_test ( "insert" , & client, & buffer , |client| async move {
363
368
client
364
369
. database ( function_name ! ( ) )
365
370
. collection :: < Document > ( function_name ! ( ) )
@@ -378,14 +383,17 @@ async fn session_usage() {
378
383
return ;
379
384
}
380
385
386
+ #[ allow( deprecated) ]
381
387
async fn session_usage_test < F , G > ( command_name : & str , operation : F )
382
388
where
383
389
F : Fn ( EventClient ) -> G ,
384
390
G : Future < Output = ( ) > ,
385
391
{
386
392
let client = EventClient :: new ( ) . await ;
387
393
operation ( client. clone ( ) ) . await ;
388
- let ( command_started, _) = client. get_successful_command_execution ( command_name) ;
394
+ let mut events = client. events . clone ( ) ;
395
+ #[ allow( deprecated) ]
396
+ let ( command_started, _) = events. get_successful_command_execution ( command_name) ;
389
397
assert ! (
390
398
command_started. command. get( "lsid" ) . is_some( ) ,
391
399
"implicit session not passed to {}" ,
@@ -400,6 +408,7 @@ async fn session_usage() {
400
408
#[ tokio:: test]
401
409
#[ function_name:: named]
402
410
async fn implicit_session_returned_after_immediate_exhaust ( ) {
411
+ #[ allow( deprecated) ]
403
412
let client = EventClient :: new ( ) . await ;
404
413
if client. is_standalone ( ) {
405
414
return ;
@@ -419,7 +428,11 @@ async fn implicit_session_returned_after_immediate_exhaust() {
419
428
let mut cursor = coll. find ( doc ! { } ) . await . expect ( "find should succeed" ) ;
420
429
assert ! ( matches!( cursor. next( ) . await , Some ( Ok ( _) ) ) ) ;
421
430
422
- let ( find_started, _) = client. get_successful_command_execution ( "find" ) ;
431
+ #[ allow( deprecated) ]
432
+ let ( find_started, _) = {
433
+ let mut events = client. events . clone ( ) ;
434
+ events. get_successful_command_execution ( "find" )
435
+ } ;
423
436
let session_id = find_started
424
437
. command
425
438
. get ( "lsid" )
@@ -440,6 +453,7 @@ async fn implicit_session_returned_after_immediate_exhaust() {
440
453
#[ tokio:: test]
441
454
#[ function_name:: named]
442
455
async fn implicit_session_returned_after_exhaust_by_get_more ( ) {
456
+ #[ allow( deprecated) ]
443
457
let client = EventClient :: new ( ) . await ;
444
458
if client. is_standalone ( ) {
445
459
return ;
@@ -468,7 +482,12 @@ async fn implicit_session_returned_after_exhaust_by_get_more() {
468
482
assert ! ( matches!( cursor. next( ) . await , Some ( Ok ( _) ) ) ) ;
469
483
}
470
484
471
- let ( find_started, _) = client. get_successful_command_execution ( "find" ) ;
485
+ #[ allow( deprecated) ]
486
+ let ( find_started, _) = {
487
+ let mut events = client. events . clone ( ) ;
488
+ events. get_successful_command_execution ( "find" )
489
+ } ;
490
+
472
491
let session_id = find_started
473
492
. command
474
493
. get ( "lsid" )
@@ -489,6 +508,7 @@ async fn implicit_session_returned_after_exhaust_by_get_more() {
489
508
#[ tokio:: test]
490
509
#[ function_name:: named]
491
510
async fn find_and_getmore_share_session ( ) {
511
+ #[ allow( deprecated) ]
492
512
let client = EventClient :: new ( ) . await ;
493
513
if client. is_standalone ( ) {
494
514
log_uncaptured (
@@ -522,6 +542,7 @@ async fn find_and_getmore_share_session() {
522
542
} ,
523
543
] ;
524
544
545
+ #[ allow( deprecated) ]
525
546
async fn run_test (
526
547
client : & EventClient ,
527
548
coll : & Collection < Document > ,
@@ -564,14 +585,17 @@ async fn find_and_getmore_share_session() {
564
585
} ) ;
565
586
}
566
587
567
- let ( find_started, _) = client. get_successful_command_execution ( "find" ) ;
588
+ let mut events = client. events . clone ( ) ;
589
+ #[ allow( deprecated) ]
590
+ let ( find_started, _) = events. get_successful_command_execution ( "find" ) ;
568
591
let session_id = find_started
569
592
. command
570
593
. get ( "lsid" )
571
594
. expect ( "find should use implicit session" ) ;
572
595
assert ! ( session_id != & Bson :: Null ) ;
573
596
574
- let ( command_started, _) = client. get_successful_command_execution ( "getMore" ) ;
597
+ #[ allow( deprecated) ]
598
+ let ( command_started, _) = events. get_successful_command_execution ( "getMore" ) ;
575
599
let getmore_session_id = command_started
576
600
. command
577
601
. get ( "lsid" )
0 commit comments