From 7da922cd5c3014917905c60a0733f4888d2ddd7c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 15 Apr 2020 19:47:05 +0100 Subject: [PATCH] test: ensure pkill is run even without exception. This should make it easier to cleanup after test failures or successes. It may also allow simplification of `test do` blocks if they can assume that all subprocesses will be killed. --- Library/Homebrew/test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index c14cb2517f..32cf7a7caa 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -37,6 +37,7 @@ begin rescue Exception => e # rubocop:disable Lint/RescueException error_pipe.puts e.to_json error_pipe.close +ensure pid = Process.pid.to_s if which("pgrep") && which("pkill") && system("pgrep", "-P", pid, out: :close) $stderr.puts "Killing child processes..." @@ -44,5 +45,5 @@ rescue Exception => e # rubocop:disable Lint/RescueException sleep 1 system "pkill", "-9", "-P", pid end - exit! 1 + exit! 1 if e end