From 94e79e4c2da8d69f45e67228a051bb1c09a367ec Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 30 Sep 2023 17:41:14 +0900 Subject: [PATCH] Fix failures when all network interfaces are down --- spec/ruby/library/socket/tcpsocket/shared/new.rb | 6 ++++++ test/socket/test_tcp.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb index d60260a01b..90f8d7e6a2 100644 --- a/spec/ruby/library/socket/tcpsocket/shared/new.rb +++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb @@ -19,6 +19,9 @@ describe :tcpsocket_new, shared: true do -> { TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) }.should raise_error(Errno::ETIMEDOUT) + rescue Errno::ENETUNREACH + # In the case all network interfaces down. + # raise_error cannot deal with multiple expected exceptions end end @@ -27,6 +30,9 @@ describe :tcpsocket_new, shared: true do -> { TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0) }.should raise_error(IO::TimeoutError) + rescue Errno::ENETUNREACH + # In the case all network interfaces down. + # raise_error cannot deal with multiple expected exceptions end end diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb index 83ebea1b7a..7f9dc53cae 100644 --- a/test/socket/test_tcp.rb +++ b/test/socket/test_tcp.rb @@ -70,7 +70,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase end def test_initialize_connect_timeout - assert_raise(IO::TimeoutError) do + assert_raise(IO::TimeoutError, Errno::ENETUNREACH) do TCPSocket.new("192.0.2.1", 80, connect_timeout: 0) end end