Commit 4ff2d130 authored by danielsdeleo's avatar danielsdeleo
Browse files

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.
parent 99001519
......@@ -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
......
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment