Skip to content

Commit

Permalink
[ruby/net-protocol] Failing test case for #19
Browse files Browse the repository at this point in the history
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
  • Loading branch information
byroot authored and matzbot committed Dec 8, 2022
1 parent 516fe62 commit 6081fd4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/net/protocol/test_protocol.rb
Expand Up @@ -119,4 +119,33 @@ def test_write0_timeout_multi2
io.write_timeout = 0.1
assert_raise(Net::WriteTimeout){ io.write("a"*50,"a"*50,"a") }
end

class FakeReadPartialIO
def initialize(chunks)
@chunks = chunks.map(&:dup)
end

def read_nonblock(size, buf = nil, exception: false)
if buf
buf.replace(@chunks.shift)
buf
else
@chunks.shift
end
end
end

def test_shareable_buffer_leak # https://github.com/ruby/net-protocol/pull/19
expected_chunks = [
"aaaaa",
"bbbbb",
]
fake_io = FakeReadPartialIO.new(expected_chunks)
io = Net::BufferedIO.new(fake_io)
actual_chunks = []
reader = Net::ReadAdapter.new(-> (chunk) { actual_chunks << chunk })
io.read(5, reader)
io.read(5, reader)
assert_equal expected_chunks, actual_chunks
end
end

0 comments on commit 6081fd4

Please sign in to comment.