@@ -72,18 +72,20 @@ def test_blocking_call
7272 client_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? 2.0 : 1.5
7373 server_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? '1' : '0.5'
7474
75- assert_equal ( %w[ foo world ] , @client . blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout ) , 'Case: 1st' )
75+ swap_timeout ( @client , timeout : 0.1 ) do |client |
76+ assert_equal ( %w[ foo world ] , client . blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout ) , 'Case: 1st' )
7677
77- # FIXME: too flaky, just a workaround
78- got = @ client. blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout )
79- if got . nil?
80- assert_nil ( got , 'Case: 2nd' )
81- else
82- assert_equal ( %w[ foo hello ] , got , 'Case: 2nd' )
83- end
78+ # FIXME: too flaky, just a workaround
79+ got = client . blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout )
80+ if got . nil?
81+ assert_nil ( got , 'Case: 2nd' )
82+ else
83+ assert_equal ( %w[ foo hello ] , got , 'Case: 2nd' )
84+ end
8485
85- assert_nil ( @client . blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout ) , 'Case: 3rd' )
86- assert_raises ( ::RedisClient ::ReadTimeoutError , 'Case: 4th' ) { @client . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
86+ assert_nil ( client . blocking_call ( client_side_timeout , 'BRPOP' , 'foo' , server_side_timeout ) , 'Case: 3rd' )
87+ assert_raises ( ::RedisClient ::ReadTimeoutError , 'Case: 4th' ) { client . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
88+ end
8789 end
8890
8991 def test_scan
@@ -146,12 +148,16 @@ def test_pipelined
146148 want = %w[ PONG ] + ( 0 ..9 ) . map ( &:to_s ) + [ %w[ list 2 ] ]
147149 client_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? 1.5 : 1.0
148150 server_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? '1' : '0.5'
149- got = @client . pipelined do |pipeline |
150- pipeline . call_once ( 'PING' )
151- 10 . times { |i | pipeline . call ( 'GET' , "string#{ i } " ) }
152- pipeline . blocking_call ( client_side_timeout , 'BRPOP' , 'list' , server_side_timeout )
151+
152+ swap_timeout ( @client , timeout : 0.1 ) do |client |
153+ got = client . pipelined do |pipeline |
154+ pipeline . call_once ( 'PING' )
155+ 10 . times { |i | pipeline . call ( 'GET' , "string#{ i } " ) }
156+ pipeline . blocking_call ( client_side_timeout , 'BRPOP' , 'list' , server_side_timeout )
157+ end
158+
159+ assert_equal ( want , got )
153160 end
154- assert_equal ( want , got )
155161 end
156162
157163 def test_pipelined_with_errors
@@ -815,8 +821,12 @@ def test_circuit_breakers
815821 )
816822 ) . new_client
817823
818- assert_raises ( ::RedisClient ::ReadTimeoutError ) { cli . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
819- assert_raises ( ::RedisClient ::CircuitBreaker ::OpenCircuitError ) { cli . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
824+ cli . call ( 'echo' , 'init' )
825+
826+ swap_timeout ( cli , timeout : 0.1 ) do |c |
827+ assert_raises ( ::RedisClient ::ReadTimeoutError ) { c . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
828+ assert_raises ( ::RedisClient ::CircuitBreaker ::OpenCircuitError ) { c . blocking_call ( 0.1 , 'BRPOP' , 'foo' , 0 ) }
829+ end
820830
821831 cli &.close
822832 end
@@ -875,7 +885,9 @@ def test_initialization_delayed
875885 def wait_for_replication
876886 client_side_timeout = TEST_TIMEOUT_SEC + 1.0
877887 server_side_timeout = ( TEST_TIMEOUT_SEC * 1000 ) . to_i
878- @client &.blocking_call ( client_side_timeout , 'WAIT' , TEST_REPLICA_SIZE , server_side_timeout )
888+ swap_timeout ( @client , timeout : 0.1 ) do |client |
889+ client &.blocking_call ( client_side_timeout , 'WAIT' , TEST_REPLICA_SIZE , server_side_timeout )
890+ end
879891 end
880892
881893 def collect_messages ( pubsub , size :, max_attempts : 30 , timeout : 1.0 )
@@ -912,6 +924,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
912924 config = ::RedisClient ::ClusterConfig . new (
913925 nodes : TEST_NODE_URIS ,
914926 fixed_hostname : TEST_FIXED_HOSTNAME ,
927+ slow_command_timeout : TEST_TIMEOUT_SEC ,
915928 middlewares : middlewares ,
916929 custom : custom ,
917930 **TEST_GENERIC_OPTIONS ,
@@ -930,6 +943,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
930943 replica : true ,
931944 replica_affinity : :random ,
932945 fixed_hostname : TEST_FIXED_HOSTNAME ,
946+ slow_command_timeout : TEST_TIMEOUT_SEC ,
933947 middlewares : middlewares ,
934948 custom : custom ,
935949 **TEST_GENERIC_OPTIONS ,
@@ -948,6 +962,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
948962 replica : true ,
949963 replica_affinity : :random_with_primary ,
950964 fixed_hostname : TEST_FIXED_HOSTNAME ,
965+ slow_command_timeout : TEST_TIMEOUT_SEC ,
951966 middlewares : middlewares ,
952967 custom : custom ,
953968 **TEST_GENERIC_OPTIONS ,
@@ -966,6 +981,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
966981 replica : true ,
967982 replica_affinity : :latency ,
968983 fixed_hostname : TEST_FIXED_HOSTNAME ,
984+ slow_command_timeout : TEST_TIMEOUT_SEC ,
969985 middlewares : middlewares ,
970986 custom : custom ,
971987 **TEST_GENERIC_OPTIONS ,
@@ -982,6 +998,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
982998 config = ::RedisClient ::ClusterConfig . new (
983999 nodes : TEST_NODE_URIS ,
9841000 fixed_hostname : TEST_FIXED_HOSTNAME ,
1001+ slow_command_timeout : TEST_TIMEOUT_SEC ,
9851002 middlewares : middlewares ,
9861003 custom : custom ,
9871004 **TEST_GENERIC_OPTIONS ,
0 commit comments