diff options
author | danielsdeleo <dan@opscode.com> | 2013-11-04 08:40:47 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-11-04 08:40:47 -0800 |
commit | 4ff2d130c3d6e68a30340175b5ce0b164ce26220 (patch) | |
tree | cc73fa22f67ff31ba6dbfebab54706147b899e79 | |
parent | 99001519bb950cda8983a8f270b45845ce349a45 (diff) | |
download | mixlib-shellout-4ff2d130c3d6e68a30340175b5ce0b164ce26220.tar.gz |
Add logging about timed-out cmd termination when possible
If a logger is configured, send `error` level messages about child
process termination for timeout violations.
-rw-r--r-- | lib/mixlib/shellout/unix.rb | 2 | ||||
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb index 546d3ee..2ffa5cd 100644 --- a/lib/mixlib/shellout/unix.rb +++ b/lib/mixlib/shellout/unix.rb @@ -302,9 +302,11 @@ module Mixlib def reap_errant_child return if attempt_reap + logger.error("Command execeded allowed execution time, sending TERM") if logger Process.kill(:TERM, @child_pid) sleep 3 return if attempt_reap + logger.error("Command did not exit from TERM, sending KILL") if logger Process.kill(:KILL, @child_pid) reap diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index ec2df8f..fa0ee51 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'logger' describe Mixlib::ShellOut do let(:shell_cmd) { options ? shell_cmd_with_options : shell_cmd_without_options } @@ -862,6 +863,24 @@ describe Mixlib::ShellOut do shell_cmd.stdout.should include("nanana cant hear you") shell_cmd.status.termsig.should == 9 end + + context "and a logger is configured" do + let(:log_output) { StringIO.new } + let(:logger) { Logger.new(log_output) } + let(:options) { {:timeout => 1, :logger => logger} } + + it "should log messages about killing the child process", :focus do + # note: let blocks don't correctly memoize if an exception is raised, + # so can't use executed_cmd + lambda { shell_cmd.run_command}.should raise_error(Mixlib::ShellOut::CommandTimeout) + shell_cmd.stdout.should include("nanana cant hear you") + shell_cmd.status.termsig.should == 9 + + log_output.string.should include("Command execeded allowed execution time, sending TERM") + log_output.string.should include("Command did not exit from TERM, sending KILL") + end + + end end end |