Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-34365] Add specs that sockets are nonblocking by default #3347

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions spec/ruby/library/socket/tcpserver/accept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@
@socket = @server.accept
@socket.should be_an_instance_of(TCPSocket)
end

it "returns a TCPSocket which is set to nonblocking" do
require 'io/nonblock'
@socket = @server.accept
@socket.should.nonblock?
end

it "returns a TCPSocket which is set to close on exec" do
@socket = @server.accept
@socket.should.close_on_exec?
end
end
end
end
11 changes: 11 additions & 0 deletions spec/ruby/library/socket/tcpsocket/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
@client.remote_address.ip_port.should == @server.local_address.ip_port
end

it "creates a socket which is set to nonblocking" do
require 'io/nonblock'
@client = TCPSocket.new(ip_address, @port)
@client.should.nonblock?
end

it "creates a socket which is set to close on exec" do
@client = TCPSocket.new(ip_address, @port)
@client.should.close_on_exec?
end

describe 'using a local address and service' do
it 'binds the client socket to the local address and service' do
@client = TCPSocket.new(ip_address, @port, ip_address, 0)
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby/library/socket/udpsocket/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
@socket.binmode?.should be_true
end

it 'sets the socket to nonblock' do
require 'io/nonblock'
@socket = UDPSocket.new(:INET)
@socket.should.nonblock?
end

it 'sets the socket to close on exec' do
@socket = UDPSocket.new(:INET)
@socket.should.close_on_exec?
end

it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do
-> {
UDPSocket.new(666)
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby/library/socket/unixserver/accept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@
@socket = @server.accept
@socket.recv(5).should == 'hello'
end

it "is set to nonblocking" do
require 'io/nonblock'
@socket = @server.accept
@socket.should.nonblock?
end

it "is set to close on exec" do
@socket = @server.accept
@socket.should.close_on_exec?
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby/library/socket/unixsocket/initialize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
it 'sets the socket to binmode' do
@socket.binmode?.should be_true
end

it 'sets the socket to nonblock' do
require 'io/nonblock'
@socket.should.nonblock?
end

it 'sets the socket to close on exec' do
@socket.should.close_on_exec?
end

end
end
end
4 changes: 4 additions & 0 deletions spec/tags/library/socket/tcpserver/accept_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fails:TCPServer#accept using IPv4 with a connected client returns a TCPSocket which is set to nonblocking
fails:TCPServer#accept using IPv4 with a connected client returns a TCPSocket which is set to close on exec
fails:TCPServer#accept using IPv6 with a connected client returns a TCPSocket which is set to nonblocking
fails:TCPServer#accept using IPv6 with a connected client returns a TCPSocket which is set to close on exec
4 changes: 4 additions & 0 deletions spec/tags/library/socket/tcpsocket/initialize_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ fails:TCPSocket#initialize raises Errno::ETIMEDOUT with :connect_timeout when no
fails:TCPSocket#initialize with a running server connects to a server when passed connect_timeout argument
fails:TCPSocket#initialize raises IO::TimeoutError with :connect_timeout when no server is listening on the given address
fails:TCPSocket#initialize with a running server does not use the given block and warns to use TCPSocket::open
fails:TCPSocket#initialize using IPv4 when a server is listening on the given address creates a socket which is set to nonblocking
fails:TCPSocket#initialize using IPv4 when a server is listening on the given address creates a socket which is set to close on exec
fails:TCPSocket#initialize using IPv6 when a server is listening on the given address creates a socket which is set to nonblocking
fails:TCPSocket#initialize using IPv6 when a server is listening on the given address creates a socket which is set to close on exec
2 changes: 2 additions & 0 deletions spec/tags/library/socket/udpsocket/initialize_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:UDPSocket#initialize sets the socket to nonblock
fails:UDPSocket#initialize sets the socket to close on exec
2 changes: 2 additions & 0 deletions spec/tags/library/socket/unixserver/accept_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:UNIXServer#accept with a client with data available the returned UNIXSocket is set to nonblocking
fails:UNIXServer#accept with a client with data available the returned UNIXSocket is set to close on exec
2 changes: 2 additions & 0 deletions spec/tags/library/socket/unixsocket/initialize_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fails:UNIXSocket#initialize using an existing socket path sets the socket to nonblock
fails:UNIXSocket#initialize using an existing socket path sets the socket to close on exec
Loading