@@ -16,7 +16,7 @@ mod cluster_async {
16
16
} ;
17
17
18
18
use futures:: prelude:: * ;
19
- use futures_time:: task:: sleep;
19
+ use futures_time:: { future :: FutureExt , task:: sleep} ;
20
20
use once_cell:: sync:: Lazy ;
21
21
use std:: ops:: Add ;
22
22
@@ -4142,6 +4142,49 @@ mod cluster_async {
4142
4142
. unwrap ( ) ;
4143
4143
}
4144
4144
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
+ . retry_wait_formula ( 1 , 1 )
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
+ cmd. query_async :: < _ , Value > ( & mut connection)
4176
+ . timeout ( futures_time:: time:: Duration :: from_millis ( 1 ) )
4177
+ . await
4178
+ . unwrap_err ( ) ;
4179
+ // we sleep here, to allow the cluster connection time to retry. We expect it won't, but without this
4180
+ // sleep the test will complete before the the runtime gave the connection time to retry, which would've made the
4181
+ // test pass regardless of whether the connection tries retrying or not.
4182
+ sleep ( Duration :: from_millis ( 10 ) . into ( ) ) . await ;
4183
+ } ) ;
4184
+
4185
+ assert_eq ! ( request_counter. load( Ordering :: Relaxed ) , 1 ) ;
4186
+ }
4187
+
4145
4188
#[ cfg( feature = "tls-rustls" ) ]
4146
4189
mod mtls_test {
4147
4190
use crate :: support:: mtls_test:: create_cluster_client_from_cluster;
0 commit comments