@@ -15,8 +15,8 @@ def test_list_of_hosts_with_first_host_successful
15
15
[ 'test2.mocked.com' , 636 ] ,
16
16
[ 'test3.mocked.com' , 636 ] ,
17
17
]
18
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 0 ] ) . once . and_return ( nil )
19
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . never
18
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 0 ] , SocketHelpers . default_socket_opts ) . once . and_return ( nil )
19
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . never
20
20
Net ::LDAP ::Connection . new ( :hosts => hosts )
21
21
end
22
22
@@ -26,9 +26,9 @@ def test_list_of_hosts_with_first_host_failure
26
26
[ 'test2.mocked.com' , 636 ] ,
27
27
[ 'test3.mocked.com' , 636 ] ,
28
28
]
29
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 0 ] ) . once . and_raise ( SocketError )
30
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 1 ] ) . once . and_return ( nil )
31
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . never
29
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 0 ] , SocketHelpers . default_socket_opts ) . once . and_raise ( SocketError )
30
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 1 ] , SocketHelpers . default_socket_opts ) . once . and_return ( nil )
31
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . never
32
32
Net ::LDAP ::Connection . new ( :hosts => hosts )
33
33
end
34
34
@@ -38,17 +38,17 @@ def test_list_of_hosts_with_all_hosts_failure
38
38
[ 'test2.mocked.com' , 636 ] ,
39
39
[ 'test3.mocked.com' , 636 ] ,
40
40
]
41
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 0 ] ) . once . and_raise ( SocketError )
42
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 1 ] ) . once . and_raise ( SocketError )
43
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . with ( *hosts [ 2 ] ) . once . and_raise ( SocketError )
44
- flexmock ( TCPSocket ) . should_receive ( :new ) . ordered . never
41
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 0 ] , SocketHelpers . default_socket_opts ) . once . and_raise ( SocketError )
42
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 1 ] , SocketHelpers . default_socket_opts ) . once . and_raise ( SocketError )
43
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . with ( *hosts [ 2 ] , SocketHelpers . default_socket_opts ) . once . and_raise ( SocketError )
44
+ flexmock ( Socket ) . should_receive ( :tcp ) . ordered . never
45
45
assert_raise Net ::LDAP ::ConnectionError do
46
46
Net ::LDAP ::Connection . new ( :hosts => hosts )
47
47
end
48
48
end
49
49
50
50
def test_result_for_connection_failed_is_set
51
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( Errno ::ECONNREFUSED )
51
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_raise ( Errno ::ECONNREFUSED )
52
52
53
53
ldap_client = Net ::LDAP . new ( host : '127.0.0.1' , port : 12345 )
54
54
@@ -67,14 +67,14 @@ def test_unresponsive_host
67
67
end
68
68
69
69
def test_blocked_port
70
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( SocketError )
70
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_raise ( SocketError )
71
71
assert_raise Net ::LDAP ::Error do
72
72
Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
73
73
end
74
74
end
75
75
76
76
def test_connection_refused
77
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( Errno ::ECONNREFUSED )
77
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_raise ( Errno ::ECONNREFUSED )
78
78
stderr = capture_stderr do
79
79
assert_raise Net ::LDAP ::ConnectionRefusedError do
80
80
Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
@@ -83,9 +83,18 @@ def test_connection_refused
83
83
assert_equal ( "Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead.\n " , stderr )
84
84
end
85
85
86
+ def test_connection_timedout
87
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_raise ( Errno ::ETIMEDOUT )
88
+ stderr = capture_stderr do
89
+ assert_raise Net ::LDAP ::Error do
90
+ Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
91
+ end
92
+ end
93
+ end
94
+
86
95
def test_raises_unknown_exceptions
87
96
error = Class . new ( StandardError )
88
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( error )
97
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_raise ( error )
89
98
assert_raise error do
90
99
Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
91
100
end
@@ -328,7 +337,7 @@ class TestLDAPConnectionErrors < Test::Unit::TestCase
328
337
def setup
329
338
@tcp_socket = flexmock ( :connection )
330
339
@tcp_socket . should_receive ( :write )
331
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_return ( @tcp_socket )
340
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_return ( @tcp_socket )
332
341
@connection = Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
333
342
end
334
343
@@ -357,7 +366,7 @@ class TestLDAPConnectionInstrumentation < Test::Unit::TestCase
357
366
def setup
358
367
@tcp_socket = flexmock ( :connection )
359
368
@tcp_socket . should_receive ( :write )
360
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_return ( @tcp_socket )
369
+ flexmock ( Socket ) . should_receive ( :tcp ) . and_return ( @tcp_socket )
361
370
362
371
@service = MockInstrumentationService . new
363
372
@connection = Net ::LDAP ::Connection . new \
0 commit comments