File tree 3 files changed +44
-4
lines changed
3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ module Connectable
25
25
# @since 2.1.0
26
26
SSL = 'ssl' . freeze
27
27
28
- # The default time in seconds to timeout a connection attempt .
28
+ # The default time in seconds to timeout an operation executed on a socket .
29
29
#
30
30
# @since 2.0.0
31
31
TIMEOUT = 5 . freeze
@@ -64,12 +64,12 @@ def connected?
64
64
!!@socket && @socket . alive?
65
65
end
66
66
67
- # Get the connection timeout.
67
+ # Get the timeout to execute an operation on a socket .
68
68
#
69
- # @example Get the connection timeout.
69
+ # @example Get the timeout to execute an operation on a socket .
70
70
# connection.timeout
71
71
#
72
- # @return [ Float ] The connection timeout in seconds.
72
+ # @return [ Float ] The operation timeout in seconds.
73
73
#
74
74
# @since 2.0.0
75
75
def timeout
Original file line number Diff line number Diff line change @@ -22,6 +22,23 @@ class Monitor
22
22
class Connection
23
23
include Connectable
24
24
25
+ # The default time in seconds to timeout a connection attempt.
26
+ #
27
+ # @since 2.1.2
28
+ CONNECT_TIMEOUT = 10 . freeze
29
+
30
+ # Get the connection timeout.
31
+ #
32
+ # @example Get the connection timeout.
33
+ # connection.timeout
34
+ #
35
+ # @return [ Float ] The connection timeout in seconds.
36
+ #
37
+ # @since 2.0.0
38
+ def timeout
39
+ @timeout ||= options [ :connect_timeout ] || CONNECT_TIMEOUT
40
+ end
41
+
25
42
# Tell the underlying socket to establish a connection to the host.
26
43
#
27
44
# @example Connect to the host.
Original file line number Diff line number Diff line change 192
192
expect ( thread . stop? ) . to be ( true )
193
193
end
194
194
end
195
+
196
+ describe '#connection' do
197
+
198
+ context 'when there is a connect_timeout option set' do
199
+
200
+ let ( :connect_timeout ) do
201
+ 1
202
+ end
203
+
204
+ let ( :monitor ) do
205
+ described_class . new ( address , listeners , TEST_OPTIONS . merge ( connect_timeout : connect_timeout ) )
206
+ end
207
+
208
+ it 'sets the value as the timeout on the connection' do
209
+ expect ( monitor . connection . timeout ) . to eq ( connect_timeout )
210
+ end
211
+
212
+ it 'set the value as the timeout on the socket' do
213
+ monitor . connection . connect!
214
+ expect ( monitor . connection . send ( :socket ) . timeout ) . to eq ( connect_timeout )
215
+ end
216
+ end
217
+ end
195
218
end
You can’t perform that action at this time.
0 commit comments