Skip to content

Commit

Permalink
[GR-34365] Add specs that sockets are nonblocking by default
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4071
  • Loading branch information
eregon committed Dec 4, 2023
2 parents 4cd14c4 + 91507d8 commit 4f786f4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 0 deletions.
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

0 comments on commit 4f786f4

Please sign in to comment.