summaryrefslogtreecommitdiff
path: root/test/socket
diff options
context:
space:
mode:
authorMisaki Shioi <31817032+shioimm@users.noreply.github.com>2025-12-17 15:02:26 +0900
committerGitHub <noreply@github.com>2025-12-17 15:02:26 +0900
commit7b5691c3b000c763faa282e1f73db96afa2ecae1 (patch)
treec5b5a430dbb959701e1f8b13ab8a6b146535f3da /test/socket
parent4c38419eb81bc388eab0d50f8b2fe6e5edd1e4c7 (diff)
`Socket.tcp` and `TCPSocket.new` raises `IO::TiemoutError` with user specified timeout (#15602)
* `Socket.tcp` and `TCPSocket.new` raises `IO::TiemoutError` with user specified timeout In https://github.com/ruby/ruby/pull/11880, `rsock_connect()` was changed to raise `IO::TimeoutError` when a user-specified timeout occurs. However, when `TCPSocket.new` attempts to connect to multiple destinations, it does not use `rsock_connect()`, and instead raises `Errno::ETIMEDOUT` on timeout. As a result, the exception class raised on timeout could differ depending on whether there were multiple destinations or not. To align this behavior with the implementation of `rsock_connect()`, this change makes `TCPSocket.new` raise `IO::TimeoutError` when a user-specified timeout occurs. Similarly, `Socket.tcp` is updated to raise `IO::TimeoutError` when a timeout occurs within the method. (Note that the existing behavior of `Addrinfo#connect_internal`, which Socket.tcp depends on internally and which raises `Errno::ETIMEDOUT` on timeout, is not changed.) * [ruby/net-http] Raise `Net::OpenTimeout` when `TCPSocket.open` raises `IO::TimeoutError`. With the changes in https://github.com/ruby/ruby/pull/15602, `TCPSocket.open` now raises `IO::TimeoutError` when a user-specified timeout occurs. This change updates #connect to handle this case accordingly. https://github.com/ruby/net-http/commit/f64109e1cf
Diffstat (limited to 'test/socket')
-rw-r--r--test/socket/test_socket.rb6
-rw-r--r--test/socket/test_tcp.rb4
2 files changed, 5 insertions, 5 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index e746aca101..686114f05c 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -909,7 +909,7 @@ class TestSocket < Test::Unit::TestCase
Addrinfo.define_singleton_method(:getaddrinfo) { |*_| sleep }
- assert_raise(Errno::ETIMEDOUT) do
+ assert_raise(IO::TimeoutError) do
Socket.tcp("localhost", port, resolv_timeout: 0.01)
end
ensure
@@ -934,7 +934,7 @@ class TestSocket < Test::Unit::TestCase
server.close
- assert_raise(Errno::ETIMEDOUT) do
+ assert_raise(IO::TimeoutError) do
Socket.tcp("localhost", port, resolv_timeout: 0.01)
end
RUBY
@@ -951,7 +951,7 @@ class TestSocket < Test::Unit::TestCase
end
end
- assert_raise(Errno::ETIMEDOUT) do
+ assert_raise(IO::TimeoutError) do
Socket.tcp("localhost", 12345, open_timeout: 0.01)
end
RUBY
diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb
index 58fe44a279..d689ab2376 100644
--- a/test/socket/test_tcp.rb
+++ b/test/socket/test_tcp.rb
@@ -80,7 +80,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
port = server.connect_address.ip_port
server.close
- assert_raise(Errno::ETIMEDOUT) do
+ assert_raise(IO::TimeoutError) do
TCPSocket.new(
"localhost",
port,
@@ -321,7 +321,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
port = server.connect_address.ip_port
server.close
- assert_raise(Errno::ETIMEDOUT) do
+ assert_raise(IO::TimeoutError) do
TCPSocket.new(
"localhost",
port,