Skip to content

Commit

Permalink
added specs for udp and tcp socket for when a buffer is passed to rec…
Browse files Browse the repository at this point in the history
…v nonblock calls (#825)
  • Loading branch information
HoneyryderChuck committed Jan 8, 2021
1 parent 5f095a1 commit 7526ccb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/socket/tcpsocket/recv_nonblock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
@socket.recv_nonblock(50).should == "TCPSocket#recv_nonblock"
end

it 'writes the read to a buffer from the socket' do
@socket = TCPSocket.new @hostname, @server.port
@socket.write "TCPSocket#recv_nonblock"

# Wait for the server to echo. This spec is testing the return
# value, not the non-blocking behavior.
#
# TODO: Figure out a good way to test non-blocking.
IO.select([@socket])
buffer = "".b
@socket.recv_nonblock(50, 0, buffer)
buffer.should == 'TCPSocket#recv_nonblock'
end

it 'returns :wait_readable in exceptionless mode' do
@socket = TCPSocket.new @hostname, @server.port
@socket.recv_nonblock(50, exception: false).should == :wait_readable
Expand Down
7 changes: 7 additions & 0 deletions library/socket/udpsocket/recvfrom_nonblock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
@server.recvfrom_nonblock(1).should be_an_instance_of(Array)
end

it 'writes the data to the buffer when one is present' do
buffer = "".b
IO.select([@server])
@server.recvfrom_nonblock(1, 0, buffer)
buffer.should == 'h'
end

describe 'the returned Array' do
before do
IO.select([@server])
Expand Down

0 comments on commit 7526ccb

Please sign in to comment.