summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMisaki Shioi <31817032+shioimm@users.noreply.github.com>2024-12-02 21:47:51 +0900
committerGitHub <noreply@github.com>2024-12-02 21:47:51 +0900
commit8f57204c19b983f37d00b3f6edc4500d93480a72 (patch)
treeabadb90b6c6204c319fe36dc84b693962efe4cd2
parentc6b8a52f7bc954923c1c329e3c7e468ff3367a6f (diff)
Avoid test failures on hosts that only support IPv4 (#12213)
To verify the behavior of HEv2, some tests were prepared. But unexpected failures occur in certain environments. This happens in environments where "localhost" resolves only to an IPv4 address during tests that verify connections to IPv6. For example, the following situation can occur: - The server process is bound to ::1. - The client socket always resolves "localhost" to 127.0.0.1 and attempts to connect to 127.0.0.1. - Since no server is bound to 127.0.0.1, an ECONNREFUSED error is raised. In such situations, the behavior of `TCPSocket.new` remains unchanged from before the introduction of HEv2. (The failures occur because tests explicitly binding to ::1 were added to verify HEv2 behavior.) This change ensures that the affected tests are skipped in environments of this kind.
Notes
Notes: Merged-By: shioimm <shioi.mm@gmail.com>
-rw-r--r--test/socket/test_tcp.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb
index 146dd200f4..6b9c4634e6 100644
--- a/test/socket/test_tcp.rb
+++ b/test/socket/test_tcp.rb
@@ -146,9 +146,11 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
return if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
begin
+ # Verify that "localhost" can be resolved to an IPv6 address
+ Socket.getaddrinfo("localhost", 0, Socket::AF_INET6)
server = TCPServer.new("::1", 0)
- rescue Errno::EADDRNOTAVAIL # IPv6 is not supported
- exit
+ rescue Socket::ResolutionError, Errno::EADDRNOTAVAIL # IPv6 is not supported
+ return
end
server_thread = Thread.new { server.accept }
@@ -192,9 +194,11 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
return if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
begin
+ # Verify that "localhost" can be resolved to an IPv6 address
+ Socket.getaddrinfo("localhost", 0, Socket::AF_INET6)
server = TCPServer.new("::1", 0)
- rescue Errno::EADDRNOTAVAIL # IPv6 is not supported
- exit
+ rescue Socket::ResolutionError, Errno::EADDRNOTAVAIL # IPv6 is not supported
+ return
end
port = server.addr[1]
@@ -290,7 +294,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
begin
server = TCPServer.new("::1", 0)
rescue Errno::EADDRNOTAVAIL # IPv6 is not supported
- exit
+ return
end
port = server.connect_address.ip_port
@@ -314,8 +318,9 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
begin
server = TCPServer.new("::1", 0)
rescue Errno::EADDRNOTAVAIL # IPv6 is not supported
- exit
+ return
end
+
port = server.connect_address.ip_port
server.close
@@ -353,7 +358,7 @@ class TestSocket_TCPSocket < Test::Unit::TestCase
begin
server = TCPServer.new("::1", 0)
rescue Errno::EADDRNOTAVAIL # IPv6 is not supported
- exit
+ return
end
server_thread = Thread.new { server.accept }