@@ -16,7 +16,7 @@ mod cluster_async {
1616 } ;
1717
1818 use futures:: prelude:: * ;
19- use futures_time:: task:: sleep;
19+ use futures_time:: { future :: FutureExt , task:: sleep} ;
2020 use once_cell:: sync:: Lazy ;
2121 use std:: ops:: Add ;
2222
@@ -4142,6 +4142,52 @@ mod cluster_async {
41424142 . unwrap ( ) ;
41434143 }
41444144
4145+ #[ test]
4146+ fn test_async_cluster_do_not_retry_when_receiver_was_dropped ( ) {
4147+ let name = "test_async_cluster_do_not_retry_when_receiver_was_dropped" ;
4148+ let cmd = cmd ( "FAKE_COMMAND" ) ;
4149+ let packed_cmd = cmd. get_packed_command ( ) ;
4150+ let request_counter = Arc :: new ( AtomicU32 :: new ( 0 ) ) ;
4151+ let cloned_req_counter = request_counter. clone ( ) ;
4152+ let MockEnv {
4153+ runtime,
4154+ async_connection : mut connection,
4155+ ..
4156+ } = MockEnv :: with_client_builder (
4157+ ClusterClient :: builder ( vec ! [ & * format!( "redis://{name}" ) ] )
4158+ . retries ( 5 )
4159+ . max_retry_wait ( 2 )
4160+ . min_retry_wait ( 2 ) ,
4161+ name,
4162+ move |received_cmd : & [ u8 ] , _| {
4163+ respond_startup ( name, received_cmd) ?;
4164+
4165+ if received_cmd == packed_cmd {
4166+ cloned_req_counter. fetch_add ( 1 , Ordering :: Relaxed ) ;
4167+ return Err ( Err ( ( ErrorKind :: TryAgain , "seriously, try again" ) . into ( ) ) ) ;
4168+ }
4169+
4170+ Err ( Ok ( Value :: Okay ) )
4171+ } ,
4172+ ) ;
4173+
4174+ runtime. block_on ( async move {
4175+ let err = cmd
4176+ . query_async :: < _ , Value > ( & mut connection)
4177+ . timeout ( futures_time:: time:: Duration :: from_millis ( 1 ) )
4178+ . await
4179+ . unwrap_err ( ) ;
4180+ assert_eq ! ( err. kind( ) , std:: io:: ErrorKind :: TimedOut ) ;
4181+
4182+ // we sleep here, to allow the cluster connection time to retry. We expect it won't, but without this
4183+ // sleep the test will complete before the the runtime gave the connection time to retry, which would've made the
4184+ // test pass regardless of whether the connection tries retrying or not.
4185+ sleep ( Duration :: from_millis ( 10 ) . into ( ) ) . await ;
4186+ } ) ;
4187+
4188+ assert_eq ! ( request_counter. load( Ordering :: Relaxed ) , 1 ) ;
4189+ }
4190+
41454191 #[ cfg( feature = "tls-rustls" ) ]
41464192 mod mtls_test {
41474193 use crate :: support:: mtls_test:: create_cluster_client_from_cluster;
0 commit comments