Skip to content

Commit

Permalink
Add spec for IO.copy_stream with partial writes
Browse files Browse the repository at this point in the history
When the receiving stream doesn't accept all data written by
IO.copy_stream, the runtime should continue attempting to write
that data until what it read has been consumed.

See jruby/jruby#6078 for an example bug in JRuby.
  • Loading branch information
headius authored and eregon committed Apr 5, 2020
1 parent 48dfe14 commit ddd89c8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions core/io/copy_stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,35 @@
end

end


describe "with a destination that does partial reads" do
before do
@from_out, @from_in = IO.pipe
@to_out, @to_in = IO.pipe
end

after do
[@from_out, @from_in, @to_out, @to_in].each {|io| io.close rescue nil}
end

it "calls #write repeatedly on the destination Object" do
@from_in.write "1234"
@from_in.close

th = Thread.new do
IO.copy_stream(@from_out, @to_in)
end

copied = ""
4.times do
copied += @to_out.read(1)
end

th.join

copied.should == "1234"
end

end
end

0 comments on commit ddd89c8

Please sign in to comment.