File tree Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Expand file tree Collapse file tree 2 files changed +16
-15
lines changed Original file line number Diff line number Diff line change 2
2
require "redis/connection/command_helper"
3
3
require "redis/errors"
4
4
require "socket"
5
+ require "timeout"
5
6
6
7
class Redis
7
8
module Connection
Original file line number Diff line number Diff line change @@ -162,25 +162,25 @@ def test_connection_timeout
162
162
163
163
driver ( :ruby ) do
164
164
def test_write_timeout
165
- redis_mock ( :write_timeout => 0.1 , :timeout => 1 ) do |redis |
166
- # This is really disgusting, but this essentially mocks the "super" call in write
167
- IO . class_eval do
168
- alias_method :old_write , :write
165
+ t = Thread . new do
166
+ TCPServer . new ( "127.0.0.1" , 6383 )
167
+ end
169
168
170
- def write ( *args )
171
- sleep 1
172
- end
173
- end
174
- assert_raise Redis ::TimeoutError do
175
- redis . rpush ( "tmp" , "test" )
169
+ begin
170
+ TCPSocket . new ( "127.0.0.1" , 6383 )
171
+ rescue Errno ::ECONNREFUSED
172
+ sleep ( 0.05 )
173
+ retry
174
+ end
175
+
176
+ assert_raise ( Redis ::TimeoutError ) do
177
+ Timeout . timeout ( 1 ) do
178
+ redis = Redis . new ( :port => 6383 , timeout : 5 , write_timeout : 0.2 )
179
+ redis . set ( "foo" , "1" * 1048576 )
176
180
end
177
181
end
178
182
ensure
179
- IO . class_eval do
180
- undef_method :write
181
- alias_method :write , :old_write
182
- undef_method :old_write
183
- end
183
+ t . join if t
184
184
end
185
185
end
186
186
You can’t perform that action at this time.
0 commit comments