Skip to content

Commit 6081fd4

Browse files
byrootmatzbot
authored andcommitted
[ruby/net-protocol] 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. ruby/net-protocol@40a1ab687c
1 parent 516fe62 commit 6081fd4

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
@@ -119,4 +119,33 @@ def test_write0_timeout_multi2
119119
io.write_timeout = 0.1
120120
assert_raise(Net::WriteTimeout){ io.write("a"*50,"a"*50,"a") }
121121
end
122+
123+
class FakeReadPartialIO
124+
def initialize(chunks)
125+
@chunks = chunks.map(&:dup)
126+
end
127+
128+
def read_nonblock(size, buf = nil, exception: false)
129+
if buf
130+
buf.replace(@chunks.shift)
131+
buf
132+
else
133+
@chunks.shift
134+
end
135+
end
136+
end
137+
138+
def test_shareable_buffer_leak # https://github.com/ruby/net-protocol/pull/19
139+
expected_chunks = [
140+
"aaaaa",
141+
"bbbbb",
142+
]
143+
fake_io = FakeReadPartialIO.new(expected_chunks)
144+
io = Net::BufferedIO.new(fake_io)
145+
actual_chunks = []
146+
reader = Net::ReadAdapter.new(-> (chunk) { actual_chunks << chunk })
147+
io.read(5, reader)
148+
io.read(5, reader)
149+
assert_equal expected_chunks, actual_chunks
150+
end
122151
end

0 commit comments

Comments
 (0)