summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 18:05:11 -0400
committerHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 18:05:11 -0400
commitab7aae4c7c5908a775d68c0a2520e9b3c93e8861 (patch)
tree74d90550c157f5d99235826405e59496cdb36bbb /spec
parent881683cb82582214b75d31d3e6e6c05e06518f4c (diff)
downloadmixlib-shellout-ab7aae4c7c5908a775d68c0a2520e9b3c93e8861.tar.gz
[CHEF-2994][RSPEC] ShellOut#run_command with subprocess that pipes lots of data through stdin, stdout, and stderr should not hang
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout/shellout_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb
index 68c12dd..b61c881 100644
--- a/spec/mixlib/shellout/shellout_spec.rb
+++ b/spec/mixlib/shellout/shellout_spec.rb
@@ -753,6 +753,30 @@ describe Mixlib::ShellOut do
end
end
+ context 'with subprocess piping lots of data through stdin, stdout, and stderr' do
+ let(:expected_output_with) { lambda { |chr| (chr * 20_000) + "#{LINE_ENDING}" + (chr * 20_000) + "#{LINE_ENDING}" } }
+ let(:ruby_code) { 'while(input = gets) do ( input[0] == "f" ? STDOUT : STDERR ).puts input; end' }
+ let(:options) { { :input => input } }
+
+ context 'when writing to STDOUT first' do
+ let(:input) { [ 'f' * 20_000, 'u' * 20_000, 'f' * 20_000, 'u' * 20_000 ].join(LINE_ENDING) }
+
+ 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(:input) { [ 'u' * 20_000, 'f' * 20_000, 'u' * 20_000, 'f' * 20_000 ].join(LINE_ENDING) }
+
+ it "should not deadlock" do
+ stdout.should eql(expected_output_with.call('f'))
+ stderr.should eql(expected_output_with.call('u'))
+ end
+ end
+ end
+
context 'when subprocess writes, pauses, then continues writing' do
subject { stdout }
let(:ruby_code) { %q{puts "before"; sleep 0.5; puts "after"} }