summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-11-01 15:16:19 -0700
committerdanielsdeleo <dan@opscode.com>2013-11-01 15:27:32 -0700
commitbc60d9b2abfbf64c848ff2e7bdb5cb69d3d84577 (patch)
tree320dee4ea27b2d4b01e2322fc3374ac099ac9a9d /spec
parentc34885b8247a5ff1d2a2ec2b63f41a6f7b0d0b52 (diff)
downloadmixlib-shellout-bc60d9b2abfbf64c848ff2e7bdb5cb69d3d84577.tar.gz
Force subprocess to exit after timeout
Fixes MIXLIB-16. This issue is particularly prominent when yum/rpm commands go off the deep end repeatedly, but affects any case where a process takes longer than the timeout to complete.
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout_spec.rb32
1 files changed, 30 insertions, 2 deletions
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb
index 9814473..d068dfc 100644
--- a/spec/mixlib/shellout_spec.rb
+++ b/spec/mixlib/shellout_spec.rb
@@ -825,12 +825,40 @@ describe Mixlib::ShellOut do
end
context 'with subprocess that takes longer than timeout' do
- let(:cmd) { ruby_eval.call('sleep 2') }
- let(:options) { { :timeout => 0.1 } }
+ let(:cmd) do
+ ruby_eval.call(<<-CODE)
+ STDOUT.sync = true
+ trap(:TERM) { puts "got term"; exit!(123) }
+ sleep 10
+ CODE
+ end
+ let(:options) { { :timeout => 1 } }
it "should raise CommandTimeout" do
lambda { executed_cmd }.should raise_error(Mixlib::ShellOut::CommandTimeout)
end
+
+ it "should ask the process nicely to exit" do
+ lambda { executed_cmd }.should raise_error(Mixlib::ShellOut::CommandTimeout)
+ executed_cmd.stdout.should include("got term")
+ executed_cmd.exitstatus.should == 123
+ end
+
+ context "and the child is unresponsive" do
+ let(:cmd) do
+ ruby_eval.call(<<-CODE)
+ STDOUT.sync = true
+ trap(:TERM) { puts "nanana cant hear you" }
+ sleep 10
+ CODE
+ end
+
+ it "should KILL the wayward child" do
+ lambda { executed_cmd }.should raise_error(Mixlib::ShellOut::CommandTimeout)
+ executed_cmd.stdout.should include("nanana cant hear you")
+ executed_cmd.status.termsig.should == 9
+ end
+ end
end
context 'with subprocess that exceeds buffersize' do