Skip to content

Commit ab03426

Browse files
committed
Add failing test case.
1 parent 1c1f0fa commit ab03426

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/io/event/selector/buffered_io.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,49 @@
7777
writer.transfer
7878
selector.select(0)
7979
end
80+
81+
it "can perform non-blocking read" do
82+
skip_if_ruby_platform(/mswin|mingw|cygwin/)
83+
84+
buffer = IO::Buffer.new(64)
85+
result = nil
86+
87+
output.puts "Hello World\n"
88+
output.close
89+
90+
reader = Fiber.new do
91+
result = selector.io_read(Fiber.current, input, buffer, 0)
92+
end
93+
94+
reader.transfer
95+
selector.select(0)
96+
97+
expect(buffer.get_string(0, 12)).to be == "Hello World\n"
98+
end
99+
100+
EAGAIN = -Errno::EAGAIN::Errno
101+
EWOULDBLOCK = -Errno::EWOULDBLOCK::Errno
102+
103+
# Whether the given error code indicates that the operation should be retried.
104+
def be_again?
105+
(be == EAGAIN).or(be == EWOULDBLOCK)
106+
end
107+
108+
it "can perform non-blocking read with empty input" do
109+
skip_if_ruby_platform(/mswin|mingw|cygwin/)
110+
111+
buffer = IO::Buffer.new(64)
112+
result = nil
113+
114+
reader = Fiber.new do
115+
result = selector.io_read(Fiber.current, input, buffer, 0)
116+
end
117+
118+
reader.transfer
119+
selector.select(0)
120+
121+
expect(result).to be_again?
122+
end
80123
end
81124
end
82125

0 commit comments

Comments
 (0)