@@ -72,18 +72,20 @@ def test_blocking_call
72
72
client_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? 2.0 : 1.5
73
73
server_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? '1' : '0.5'
74
74
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' )
76
77
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
84
85
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
87
89
end
88
90
89
91
def test_scan
@@ -146,12 +148,16 @@ def test_pipelined
146
148
want = %w[ PONG ] + ( 0 ..9 ) . map ( &:to_s ) + [ %w[ list 2 ] ]
147
149
client_side_timeout = TEST_REDIS_MAJOR_VERSION < 6 ? 1.5 : 1.0
148
150
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 )
153
160
end
154
- assert_equal ( want , got )
155
161
end
156
162
157
163
def test_pipelined_with_errors
@@ -815,8 +821,12 @@ def test_circuit_breakers
815
821
)
816
822
) . new_client
817
823
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
820
830
821
831
cli &.close
822
832
end
@@ -875,7 +885,9 @@ def test_initialization_delayed
875
885
def wait_for_replication
876
886
client_side_timeout = TEST_TIMEOUT_SEC + 1.0
877
887
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
879
891
end
880
892
881
893
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
912
924
config = ::RedisClient ::ClusterConfig . new (
913
925
nodes : TEST_NODE_URIS ,
914
926
fixed_hostname : TEST_FIXED_HOSTNAME ,
927
+ slow_command_timeout : TEST_TIMEOUT_SEC ,
915
928
middlewares : middlewares ,
916
929
custom : custom ,
917
930
**TEST_GENERIC_OPTIONS ,
@@ -930,6 +943,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
930
943
replica : true ,
931
944
replica_affinity : :random ,
932
945
fixed_hostname : TEST_FIXED_HOSTNAME ,
946
+ slow_command_timeout : TEST_TIMEOUT_SEC ,
933
947
middlewares : middlewares ,
934
948
custom : custom ,
935
949
**TEST_GENERIC_OPTIONS ,
@@ -948,6 +962,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
948
962
replica : true ,
949
963
replica_affinity : :random_with_primary ,
950
964
fixed_hostname : TEST_FIXED_HOSTNAME ,
965
+ slow_command_timeout : TEST_TIMEOUT_SEC ,
951
966
middlewares : middlewares ,
952
967
custom : custom ,
953
968
**TEST_GENERIC_OPTIONS ,
@@ -966,6 +981,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
966
981
replica : true ,
967
982
replica_affinity : :latency ,
968
983
fixed_hostname : TEST_FIXED_HOSTNAME ,
984
+ slow_command_timeout : TEST_TIMEOUT_SEC ,
969
985
middlewares : middlewares ,
970
986
custom : custom ,
971
987
**TEST_GENERIC_OPTIONS ,
@@ -982,6 +998,7 @@ def new_test_client(custom: { captured_commands: @captured_commands }, middlewar
982
998
config = ::RedisClient ::ClusterConfig . new (
983
999
nodes : TEST_NODE_URIS ,
984
1000
fixed_hostname : TEST_FIXED_HOSTNAME ,
1001
+ slow_command_timeout : TEST_TIMEOUT_SEC ,
985
1002
middlewares : middlewares ,
986
1003
custom : custom ,
987
1004
**TEST_GENERIC_OPTIONS ,
0 commit comments