From 274dee188ba467c5876796ff12ac82821c9bd2e3 Mon Sep 17 00:00:00 2001 From: Ho-Sheng Hsiao Date: Fri, 23 Mar 2012 16:00:09 -0400 Subject: [RSPEC] Refactored spec for dumping lots of data through STDOUT and STDERR --- spec/mixlib/shellout/shellout_spec.rb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb index 4f587ad0de..690b6dfb90 100644 --- a/spec/mixlib/shellout/shellout_spec.rb +++ b/spec/mixlib/shellout/shellout_spec.rb @@ -591,20 +591,25 @@ describe Mixlib::ShellOut do end end - it "does not deadlock when the subprocess writes lots of data to both stdout and stderr" do - chatty = %q{ruby -e "puts 'f' * 20_000;STDERR.puts 'u' * 20_000; puts 'f' * 20_000;STDERR.puts 'u' * 20_000"} - cmd = Mixlib::ShellOut.new(chatty) - cmd.run_command - cmd.stdout.should == ('f' * 20_000) + "#{LINE_ENDING}" + ('f' * 20_000) + "#{LINE_ENDING}" - cmd.stderr.should == ('u' * 20_000) + "#{LINE_ENDING}" + ('u' * 20_000) + "#{LINE_ENDING}" - end + context 'with subprocess writing lots of data to both stdout and stderr' do + let(:cmd) { ruby_eval.call(chatty) } + let(:expected_output_with) { lambda { |chr| (chr * 20_000) + "#{LINE_ENDING}" + (chr * 20_000) + "#{LINE_ENDING}" } } - it "does not deadlock when the subprocess writes lots of data to both stdout and stderr (part2)" do - chatty = %q{ruby -e "STDERR.puts 'u' * 20_000; puts 'f' * 20_000;STDERR.puts 'u' * 20_000; puts 'f' * 20_000"} - cmd = Mixlib::ShellOut.new(chatty) - cmd.run_command - cmd.stdout.should == ('f' * 20_000) + "#{LINE_ENDING}" + ('f' * 20_000) + "#{LINE_ENDING}" - cmd.stderr.should == ('u' * 20_000) + "#{LINE_ENDING}" + ('u' * 20_000) + "#{LINE_ENDING}" + context 'when writing to STDOUT first' do + let(:chatty) { %q{puts "f" * 20_000; STDERR.puts "u" * 20_000; puts "f" * 20_000; STDERR.puts "u" * 20_000} } + it "should not deadlock" do + stdout.should eql(expected_output_with.call('f')) + stderr.should eql(expected_output_with.call('u')) + end + end + + context 'when writing to STDERR first' do + let(:chatty) { %q{STDERR.puts "u" * 20_000; puts "f" * 20_000; STDERR.puts "u" * 20_000; puts "f" * 20_000} } + it "should not deadlock" do + stdout.should eql(expected_output_with.call('f')) + stderr.should eql(expected_output_with.call('u')) + end + end end it "doesn't hang or lose output when a process writes, pauses, then continues writing" do -- cgit v1.2.1