Skip to content

Commit 8fe32ac

Browse files
committed
Add spec for nonblock Socket APIs with exception: false
1 parent 697c6e4 commit 8fe32ac

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
}
3636
end
3737

38+
it "returns :wait_readable with exception: false" do
39+
@s1.bind(Socket.pack_sockaddr_in(0, ip_address))
40+
@s1.recv_nonblock(5, exception: false).should == :wait_readable
41+
end
42+
3843
it "receives data after it's ready" do
3944
@s1.bind(Socket.pack_sockaddr_in(0, ip_address))
4045
@s2.send("aaa", 0, @s1.getsockname)

spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
it 'raises an exception extending IO::WaitReadable' do
3232
lambda { @server.recvmsg_nonblock }.should raise_error(IO::WaitReadable)
3333
end
34+
35+
it 'returns :wait_readable with exception: false' do
36+
@server.recvmsg_nonblock(exception: false).should == :wait_readable
37+
end
3438
end
3539

3640
describe 'with data available' do

spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@
9898
10.times { @client.sendmsg_nonblock('hello' * 1_000_000) }
9999
}.should raise_error(IO::WaitWritable)
100100
end
101+
102+
it 'returns :wait_writable when the underlying buffer is full with exception: false' do
103+
ret = nil
104+
10.times {
105+
ret = @client.sendmsg_nonblock('hello' * 1_000_000, exception: false)
106+
break unless ret.is_a?(Integer)
107+
}
108+
ret.should == :wait_writable
109+
end
101110
end
102111
end
103112
end

spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
it 'raises IO::WaitReadable' do
3232
lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
3333
end
34+
35+
it 'returns :wait_readable with exception: false' do
36+
@server.recvfrom_nonblock(1, exception: false).should == :wait_readable
37+
end
3438
end
3539

3640
describe 'with data available' do

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
it 'raises IO::WaitReadable' do
3535
lambda { @server.recvfrom_nonblock(1) }.should raise_error(IO::WaitReadable)
3636
end
37+
38+
it 'returns :wait_readable with exception: false' do
39+
@server.recvfrom_nonblock(1, exception: false).should == :wait_readable
40+
end
3741
end
3842

3943
platform_is_not :windows do

0 commit comments

Comments
 (0)