File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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
130159end
You can’t perform that action at this time.
0 commit comments