From d81eabf93238071113cd18fc326b45efcd5b745d Mon Sep 17 00:00:00 2001 From: Misaki Shioi <31817032+shioimm@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:14:05 +0900 Subject: [PATCH] Allow Net::HTTP#request to raise Net::OpenTimeout (#12062) with a TCPSoerver that is only listening to avoid AssertionFailedError on Ubuntu. --- The tests such as `TestNetHTTP_v1_2_chunked#test_timeout_during_non_chunked_streamed_HTTP_session_write` expect to raise a `Net::WriteTimeout` due to a failure in writing to the server. However, on Ubuntu environments, the server immediately returns a "Connection Refused" in such cases. The socket created with `TCPSocket.new` that supports HEv2 catches this immediately and raises a `Net::OpenTimeout`. As a result, these tests fail due to raising a different exception than expected. This PR adds `Net::OpenTimeout` asexceptions to avoid these test failures. --- test/net/http/test_http.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index a49cc87..25fdead 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -568,8 +568,8 @@ def test_timeout_during_HTTP_session_write conn.open_timeout = EnvUtil.apply_timeout_scale(0.1) th = Thread.new do - err = !windows? ? Net::WriteTimeout : Net::ReadTimeout - assert_raise(err) do + err = !windows? ? [Net::WriteTimeout, Net::OpenTimeout] : Net::ReadTimeout + assert_raise(*err) do assert_warning(/Content-Type did not set/) do conn.post('/', "a"*50_000_000) end @@ -600,7 +600,7 @@ def test_timeout_during_non_chunked_streamed_HTTP_session_write req.body_stream = StringIO.new(data) th = Thread.new do - assert_raise(Net::WriteTimeout) { conn.request(req) } + assert_raise(Net::WriteTimeout, Net::OpenTimeout) { conn.request(req) } end assert th.join(10) }