From cbb4de9fd775342b307deef997f9e08aa9f54cd8 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Fri, 7 Mar 2014 10:37:54 -0800 Subject: Add debugging to volatile specs Attempting to reproduce this in isolation hasn't worked. Add debug information permanently so we may get a hint of why this test sometimes fails if we see it again. --- spec/mixlib/shellout_spec.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index 3d0a04f..42f2714 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -944,19 +944,37 @@ describe Mixlib::ShellOut do CODE end + it "should TERM the wayward child and grandchild, then KILL whoever is left" 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("got term in child") - shell_cmd.stdout.should include("got term in grandchild") + begin - # A little janky. We get the process group id out of the command - # object, then try to kill a process in it to make sure none - # exists. Trusting the system under test like this isn't great but - # it's difficult to test otherwise. - lambda { Process.kill(:INT, shell_cmd.send(:child_pgid)) }.should raise_error(Errno::ESRCH) + # A little janky. We get the process group id out of the command + # object, then try to kill a process in it to make sure none + # exists. Trusting the system under test like this isn't great but + # it's difficult to test otherwise. + child_pgid = shell_cmd.send(:child_pgid) + initial_process_listing = `ps -j` + + shell_cmd.stdout.should include("got term in child") + shell_cmd.stdout.should include("got term in grandchild") + + Process.kill(:INT, child_pgid) # should raise ESRCH + + # Debug the failure: + puts "child pgid=#{child_pgid.inspect}" + Process.wait + puts "collected process: #{$?.inspect}" + puts "initial process listing:\n#{initial_process_listing}" + puts "current process listing:" + puts `ps -j` + raise "Failed to kill all expected processes" + rescue Errno::ESRCH + # this is what we want + end end end -- cgit v1.2.1