Skip to content

Commit

Permalink
Add test for IO-like objects in IO.copy_stream. #4796
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 11, 2018
1 parent a512032 commit cc93db8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/io/FilenoUtil.java
Expand Up @@ -84,6 +84,7 @@ public void unregisterWrapper(int fileno) {
filenoMap.remove(fileno);
}

// Used by testing. See test/jruby/test_io.rb, test_io_copy_stream_does_not_leak_io_like_objects
public int getNumberOfWrappers() {
return filenoMap.size();
}
Expand Down
28 changes: 28 additions & 0 deletions test/jruby/test_io.rb
Expand Up @@ -580,4 +580,32 @@ def test_stringio_gets_nil_separator_limit
assert_equal 'ab', stringio.gets(nil, 2)
end

# jruby/jruby#4796
def test_io_copy_stream_does_not_leak_io_like_objects
in_stream = Tempfile.new('4796')
in_stream.write('1234567890')
in_stream.rewind

out_stream = Object.new
def out_stream.write(stuff)
stuff.length
end
def out_stream.read(*n)
nil
end

fu = JRuby.runtime.fileno_util

before = fu.number_of_wrappers

100.times do
IO.copy_stream(in_stream, out_stream)
IO.copy_stream(out_stream, in_stream)
end

after = fu.number_of_wrappers

assert_equal before, after, "no wrappers should have been registered"
end

end

0 comments on commit cc93db8

Please sign in to comment.