diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2022-12-08 09:44:58 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-12-08 12:15:52 +0000 |
commit | 6081fd456436a98ada7f51ebb4d44c0cc7f01b06 (patch) | |
tree | 25e18381e0d25544cb9f5e6a0d190ba2b81ea819 | |
parent | 516fe6273454cfa7edfffe7d154ca41c8cd782a8 (diff) |
[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.
https://github.com/ruby/net-protocol/commit/40a1ab687c
-rw-r--r-- | test/net/protocol/test_protocol.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/net/protocol/test_protocol.rb b/test/net/protocol/test_protocol.rb index d3dc2ccf4c..1e38dd6c26 100644 --- a/test/net/protocol/test_protocol.rb +++ b/test/net/protocol/test_protocol.rb @@ -119,4 +119,33 @@ class TestProtocol < Test::Unit::TestCase 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 |