@@ -238,7 +238,7 @@ pub mod async_tests {
238
238
use redis:: {
239
239
aio:: MultiplexedConnection ,
240
240
sentinel:: { Sentinel , SentinelClient , SentinelNodeConnectionInfo } ,
241
- Client , ConnectionAddr , RedisError ,
241
+ AsyncConnectionConfig , Client , ConnectionAddr , RedisError ,
242
242
} ;
243
243
244
244
use crate :: { assert_is_master_role, assert_replica_role_and_master_addr, support:: * } ;
@@ -486,4 +486,167 @@ pub mod async_tests {
486
486
} )
487
487
. unwrap ( ) ;
488
488
}
489
+
490
+ #[ test]
491
+ fn test_sentinel_client_async_with_connection_timeout ( ) {
492
+ let master_name = "master1" ;
493
+ let mut context = TestSentinelContext :: new ( 2 , 3 , 3 ) ;
494
+ let mut master_client = SentinelClient :: build (
495
+ context. sentinels_connection_info ( ) . clone ( ) ,
496
+ String :: from ( master_name) ,
497
+ Some ( context. sentinel_node_connection_info ( ) ) ,
498
+ redis:: sentinel:: SentinelServerType :: Master ,
499
+ )
500
+ . unwrap ( ) ;
501
+
502
+ let mut replica_client = SentinelClient :: build (
503
+ context. sentinels_connection_info ( ) . clone ( ) ,
504
+ String :: from ( master_name) ,
505
+ Some ( context. sentinel_node_connection_info ( ) ) ,
506
+ redis:: sentinel:: SentinelServerType :: Replica ,
507
+ )
508
+ . unwrap ( ) ;
509
+
510
+ let connection_options =
511
+ AsyncConnectionConfig :: new ( ) . with_connection_timeout ( std:: time:: Duration :: from_secs ( 1 ) ) ;
512
+
513
+ block_on_all ( async move {
514
+ let mut master_con = master_client
515
+ . get_async_connection_with_config ( & connection_options)
516
+ . await ?;
517
+
518
+ async_assert_is_connection_to_master ( & mut master_con) . await ;
519
+
520
+ let node_conn_info = context. sentinel_node_connection_info ( ) ;
521
+ let sentinel = context. sentinel_mut ( ) ;
522
+ let master_client = sentinel
523
+ . async_master_for ( master_name, Some ( & node_conn_info) )
524
+ . await ?;
525
+
526
+ // Read commands to the replica node
527
+ for _ in 0 ..20 {
528
+ let mut replica_con = replica_client
529
+ . get_async_connection_with_config ( & connection_options)
530
+ . await ?;
531
+
532
+ async_assert_connection_is_replica_of_correct_master (
533
+ & mut replica_con,
534
+ & master_client,
535
+ )
536
+ . await ;
537
+ }
538
+
539
+ Ok :: < ( ) , RedisError > ( ( ) )
540
+ } )
541
+ . unwrap ( ) ;
542
+ }
543
+
544
+ #[ test]
545
+ fn test_sentinel_client_async_with_response_timeout ( ) {
546
+ let master_name = "master1" ;
547
+ let mut context = TestSentinelContext :: new ( 2 , 3 , 3 ) ;
548
+ let mut master_client = SentinelClient :: build (
549
+ context. sentinels_connection_info ( ) . clone ( ) ,
550
+ String :: from ( master_name) ,
551
+ Some ( context. sentinel_node_connection_info ( ) ) ,
552
+ redis:: sentinel:: SentinelServerType :: Master ,
553
+ )
554
+ . unwrap ( ) ;
555
+
556
+ let mut replica_client = SentinelClient :: build (
557
+ context. sentinels_connection_info ( ) . clone ( ) ,
558
+ String :: from ( master_name) ,
559
+ Some ( context. sentinel_node_connection_info ( ) ) ,
560
+ redis:: sentinel:: SentinelServerType :: Replica ,
561
+ )
562
+ . unwrap ( ) ;
563
+
564
+ let connection_options =
565
+ AsyncConnectionConfig :: new ( ) . with_response_timeout ( std:: time:: Duration :: from_secs ( 1 ) ) ;
566
+
567
+ block_on_all ( async move {
568
+ let mut master_con = master_client
569
+ . get_async_connection_with_config ( & connection_options)
570
+ . await ?;
571
+
572
+ async_assert_is_connection_to_master ( & mut master_con) . await ;
573
+
574
+ let node_conn_info = context. sentinel_node_connection_info ( ) ;
575
+ let sentinel = context. sentinel_mut ( ) ;
576
+ let master_client = sentinel
577
+ . async_master_for ( master_name, Some ( & node_conn_info) )
578
+ . await ?;
579
+
580
+ // Read commands to the replica node
581
+ for _ in 0 ..20 {
582
+ let mut replica_con = replica_client
583
+ . get_async_connection_with_config ( & connection_options)
584
+ . await ?;
585
+
586
+ async_assert_connection_is_replica_of_correct_master (
587
+ & mut replica_con,
588
+ & master_client,
589
+ )
590
+ . await ;
591
+ }
592
+
593
+ Ok :: < ( ) , RedisError > ( ( ) )
594
+ } )
595
+ . unwrap ( ) ;
596
+ }
597
+
598
+ #[ test]
599
+ fn test_sentinel_client_async_with_timeouts ( ) {
600
+ let master_name = "master1" ;
601
+ let mut context = TestSentinelContext :: new ( 2 , 3 , 3 ) ;
602
+ let mut master_client = SentinelClient :: build (
603
+ context. sentinels_connection_info ( ) . clone ( ) ,
604
+ String :: from ( master_name) ,
605
+ Some ( context. sentinel_node_connection_info ( ) ) ,
606
+ redis:: sentinel:: SentinelServerType :: Master ,
607
+ )
608
+ . unwrap ( ) ;
609
+
610
+ let mut replica_client = SentinelClient :: build (
611
+ context. sentinels_connection_info ( ) . clone ( ) ,
612
+ String :: from ( master_name) ,
613
+ Some ( context. sentinel_node_connection_info ( ) ) ,
614
+ redis:: sentinel:: SentinelServerType :: Replica ,
615
+ )
616
+ . unwrap ( ) ;
617
+
618
+ let connection_options = AsyncConnectionConfig :: new ( )
619
+ . with_connection_timeout ( std:: time:: Duration :: from_secs ( 1 ) )
620
+ . with_response_timeout ( std:: time:: Duration :: from_secs ( 1 ) ) ;
621
+
622
+ block_on_all ( async move {
623
+ let mut master_con = master_client
624
+ . get_async_connection_with_config ( & connection_options)
625
+ . await ?;
626
+
627
+ async_assert_is_connection_to_master ( & mut master_con) . await ;
628
+
629
+ let node_conn_info = context. sentinel_node_connection_info ( ) ;
630
+ let sentinel = context. sentinel_mut ( ) ;
631
+ let master_client = sentinel
632
+ . async_master_for ( master_name, Some ( & node_conn_info) )
633
+ . await ?;
634
+
635
+ // Read commands to the replica node
636
+ for _ in 0 ..20 {
637
+ let mut replica_con = replica_client
638
+ . get_async_connection_with_config ( & connection_options)
639
+ . await ?;
640
+
641
+ async_assert_connection_is_replica_of_correct_master (
642
+ & mut replica_con,
643
+ & master_client,
644
+ )
645
+ . await ;
646
+ }
647
+
648
+ Ok :: < ( ) , RedisError > ( ( ) )
649
+ } )
650
+ . unwrap ( ) ;
651
+ }
489
652
}
0 commit comments