Skip to content

Commit 94e79e4

Browse files
committed
Fix failures when all network interfaces are down
1 parent 1fbccd0 commit 94e79e4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

spec/ruby/library/socket/tcpsocket/shared/new.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-> {
2020
TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
2121
}.should raise_error(Errno::ETIMEDOUT)
22+
rescue Errno::ENETUNREACH
23+
# In the case all network interfaces down.
24+
# raise_error cannot deal with multiple expected exceptions
2225
end
2326
end
2427

@@ -27,6 +30,9 @@
2730
-> {
2831
TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
2932
}.should raise_error(IO::TimeoutError)
33+
rescue Errno::ENETUNREACH
34+
# In the case all network interfaces down.
35+
# raise_error cannot deal with multiple expected exceptions
3036
end
3137
end
3238

test/socket/test_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_initialize_resolv_timeout
7070
end
7171

7272
def test_initialize_connect_timeout
73-
assert_raise(IO::TimeoutError) do
73+
assert_raise(IO::TimeoutError, Errno::ENETUNREACH) do
7474
TCPSocket.new("192.0.2.1", 80, connect_timeout: 0)
7575
end
7676
end

0 commit comments

Comments
 (0)