From ddd89c828eb889ad805951ff0284886490479809 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 31 Mar 2020 15:37:30 -0500 Subject: [PATCH] Add spec for IO.copy_stream with partial writes 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. --- core/io/copy_stream_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/io/copy_stream_spec.rb b/core/io/copy_stream_spec.rb index c541e96e14..80b48cedfc 100644 --- a/core/io/copy_stream_spec.rb +++ b/core/io/copy_stream_spec.rb @@ -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