Skip to content

Commit

Permalink
Allow Net::HTTP#request to raise Net::OpenTimeout (#12062)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shioimm authored and hsbt committed Nov 14, 2024
1 parent 28a4bf9 commit d81eabf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d81eabf

Please sign in to comment.