Skip to content

Commit 40a1ab6

Browse files
committed
Failing test case for #19
Unfortunately we have to use a mock, but this test demonstrate the mutation bug fixed in #19. It fails on 0.2.0 but passes on 0.1.3 or 0.2.1.
1 parent 06d1420 commit 40a1ab6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/net/protocol/test_protocol.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,33 @@ def test_write0_timeout_multi2
127127
io.write_timeout = 0.1
128128
assert_raise(Net::WriteTimeout){ io.write("a"*50,"a"*50,"a") }
129129
end
130+
131+
class FakeReadPartialIO
132+
def initialize(chunks)
133+
@chunks = chunks.map(&:dup)
134+
end
135+
136+
def read_nonblock(size, buf = nil, exception: false)
137+
if buf
138+
buf.replace(@chunks.shift)
139+
buf
140+
else
141+
@chunks.shift
142+
end
143+
end
144+
end
145+
146+
def test_shareable_buffer_leak # https://github.com/ruby/net-protocol/pull/19
147+
expected_chunks = [
148+
"aaaaa",
149+
"bbbbb",
150+
]
151+
fake_io = FakeReadPartialIO.new(expected_chunks)
152+
io = Net::BufferedIO.new(fake_io)
153+
actual_chunks = []
154+
reader = Net::ReadAdapter.new(-> (chunk) { actual_chunks << chunk })
155+
io.read(5, reader)
156+
io.read(5, reader)
157+
assert_equal expected_chunks, actual_chunks
158+
end
130159
end

0 commit comments

Comments
 (0)