Skip to content

Commit

Permalink
Update specs to run with IPv6 support disabled (#15046)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Nov 13, 2024
1 parent 489cdf1 commit 2725705
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private def unix_request(path)
end

private def unused_port
TCPServer.open(0) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |server|
server.local_address.port
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/std/openssl/ssl/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require "../../../support/ssl"

describe OpenSSL::SSL::Server do
it "sync_close" do
TCPServer.open(0) do |tcp_server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |tcp_server|
context = OpenSSL::SSL::Context::Server.new
ssl_server = OpenSSL::SSL::Server.new(tcp_server, context)

Expand All @@ -22,7 +22,7 @@ describe OpenSSL::SSL::Server do
end

it "don't sync_close" do
TCPServer.open(0) do |tcp_server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |tcp_server|
context = OpenSSL::SSL::Context::Server.new
ssl_server = OpenSSL::SSL::Server.new(tcp_server, context, sync_close: false)
ssl_server.context.should eq context
Expand All @@ -35,7 +35,7 @@ describe OpenSSL::SSL::Server do

it ".new" do
context = OpenSSL::SSL::Context::Server.new
TCPServer.open(0) do |tcp_server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |tcp_server|
ssl_server = OpenSSL::SSL::Server.new tcp_server, context, sync_close: false

ssl_server.context.should eq context
Expand All @@ -46,7 +46,7 @@ describe OpenSSL::SSL::Server do

it ".open" do
context = OpenSSL::SSL::Context::Server.new
TCPServer.open(0) do |tcp_server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |tcp_server|
ssl_server = nil
OpenSSL::SSL::Server.open tcp_server, context do |server|
server.wrapped.should eq tcp_server
Expand Down
4 changes: 2 additions & 2 deletions spec/std/socket/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module SocketSpecHelper
class_getter?(supports_ipv6 : Bool) do
TCPServer.open("::1", 0) { return true }
false
rescue Socket::BindError
rescue Socket::Error
false
end
end
Expand Down Expand Up @@ -33,7 +33,7 @@ def each_ip_family(&block : Socket::Family, String, String ->)
end

def unused_local_port
TCPServer.open("::", 0) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, 0) do |server|
server.local_address.port
end
end
2 changes: 1 addition & 1 deletion spec/std/socket/tcp_server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe TCPServer, tags: "network" do

it "binds to all interfaces" do
port = unused_local_port
TCPServer.open(port) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, port) do |server|
server.local_address.port.should eq port
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/std/socket/tcp_socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ describe TCPSocket, tags: "network" do
end

it "fails to connect IPv6 to IPv4 server" do
pending! "IPv6 is unavailable" unless SocketSpecHelper.supports_ipv6?

port = unused_local_port

TCPServer.open("0.0.0.0", port) do |server|
Expand All @@ -133,7 +135,7 @@ describe TCPSocket, tags: "network" do
it "sync from server" do
port = unused_local_port

TCPServer.open("::", port) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, port) do |server|
TCPSocket.open("localhost", port) do |client|
sock = server.accept
sock.sync?.should eq(server.sync?)
Expand All @@ -152,7 +154,7 @@ describe TCPSocket, tags: "network" do
it "settings" do
port = unused_local_port

TCPServer.open("::", port) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, port) do |server|
TCPSocket.open("localhost", port) do |client|
# test protocol specific socket options
(client.tcp_nodelay = true).should be_true
Expand Down Expand Up @@ -202,7 +204,7 @@ describe TCPSocket, tags: "network" do

channel = Channel(Exception?).new
spawn do
TCPServer.open("::", port) do |server|
TCPServer.open(Socket::IPAddress::UNSPECIFIED, port) do |server|
channel.send nil
sock = server.accept
sock.read_timeout = 3.second
Expand Down

0 comments on commit 2725705

Please sign in to comment.