Skip to content

Commit 4f786f4

Browse files
committed
[GR-34365] Add specs that sockets are nonblocking by default
PullRequest: truffleruby/4071
2 parents 4cd14c4 + 91507d8 commit 4f786f4

File tree

10 files changed

+68
-0
lines changed

10 files changed

+68
-0
lines changed

spec/ruby/library/socket/tcpserver/accept_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@
114114
@socket = @server.accept
115115
@socket.should be_an_instance_of(TCPSocket)
116116
end
117+
118+
it "returns a TCPSocket which is set to nonblocking" do
119+
require 'io/nonblock'
120+
@socket = @server.accept
121+
@socket.should.nonblock?
122+
end
123+
124+
it "returns a TCPSocket which is set to close on exec" do
125+
@socket = @server.accept
126+
@socket.should.close_on_exec?
127+
end
117128
end
118129
end
119130
end

spec/ruby/library/socket/tcpsocket/initialize_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272
@client.remote_address.ip_port.should == @server.local_address.ip_port
7373
end
7474

75+
it "creates a socket which is set to nonblocking" do
76+
require 'io/nonblock'
77+
@client = TCPSocket.new(ip_address, @port)
78+
@client.should.nonblock?
79+
end
80+
81+
it "creates a socket which is set to close on exec" do
82+
@client = TCPSocket.new(ip_address, @port)
83+
@client.should.close_on_exec?
84+
end
85+
7586
describe 'using a local address and service' do
7687
it 'binds the client socket to the local address and service' do
7788
@client = TCPSocket.new(ip_address, @port, ip_address, 0)

spec/ruby/library/socket/udpsocket/initialize_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
@socket.binmode?.should be_true
3131
end
3232

33+
it 'sets the socket to nonblock' do
34+
require 'io/nonblock'
35+
@socket = UDPSocket.new(:INET)
36+
@socket.should.nonblock?
37+
end
38+
39+
it 'sets the socket to close on exec' do
40+
@socket = UDPSocket.new(:INET)
41+
@socket.should.close_on_exec?
42+
end
43+
3344
it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do
3445
-> {
3546
UDPSocket.new(666)

spec/ruby/library/socket/unixserver/accept_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@
110110
@socket = @server.accept
111111
@socket.recv(5).should == 'hello'
112112
end
113+
114+
it "is set to nonblocking" do
115+
require 'io/nonblock'
116+
@socket = @server.accept
117+
@socket.should.nonblock?
118+
end
119+
120+
it "is set to close on exec" do
121+
@socket = @server.accept
122+
@socket.should.close_on_exec?
123+
end
113124
end
114125
end
115126
end

spec/ruby/library/socket/unixsocket/initialize_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
it 'sets the socket to binmode' do
3434
@socket.binmode?.should be_true
3535
end
36+
37+
it 'sets the socket to nonblock' do
38+
require 'io/nonblock'
39+
@socket.should.nonblock?
40+
end
41+
42+
it 'sets the socket to close on exec' do
43+
@socket.should.close_on_exec?
44+
end
45+
3646
end
3747
end
3848
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fails:TCPServer#accept using IPv4 with a connected client returns a TCPSocket which is set to nonblocking
2+
fails:TCPServer#accept using IPv4 with a connected client returns a TCPSocket which is set to close on exec
3+
fails:TCPServer#accept using IPv6 with a connected client returns a TCPSocket which is set to nonblocking
4+
fails:TCPServer#accept using IPv6 with a connected client returns a TCPSocket which is set to close on exec

spec/tags/library/socket/tcpsocket/initialize_tags.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ fails:TCPSocket#initialize raises Errno::ETIMEDOUT with :connect_timeout when no
22
fails:TCPSocket#initialize with a running server connects to a server when passed connect_timeout argument
33
fails:TCPSocket#initialize raises IO::TimeoutError with :connect_timeout when no server is listening on the given address
44
fails:TCPSocket#initialize with a running server does not use the given block and warns to use TCPSocket::open
5+
fails:TCPSocket#initialize using IPv4 when a server is listening on the given address creates a socket which is set to nonblocking
6+
fails:TCPSocket#initialize using IPv4 when a server is listening on the given address creates a socket which is set to close on exec
7+
fails:TCPSocket#initialize using IPv6 when a server is listening on the given address creates a socket which is set to nonblocking
8+
fails:TCPSocket#initialize using IPv6 when a server is listening on the given address creates a socket which is set to close on exec
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fails:UDPSocket#initialize sets the socket to nonblock
2+
fails:UDPSocket#initialize sets the socket to close on exec
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fails:UNIXServer#accept with a client with data available the returned UNIXSocket is set to nonblocking
2+
fails:UNIXServer#accept with a client with data available the returned UNIXSocket is set to close on exec
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fails:UNIXSocket#initialize using an existing socket path sets the socket to nonblock
2+
fails:UNIXSocket#initialize using an existing socket path sets the socket to close on exec

0 commit comments

Comments
 (0)