From 024b6f5fec7b9a443f8387266870b831010571d9 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Wed, 11 Oct 2023 11:58:40 +0200 Subject: [PATCH] Reap processes before checking for them Unlike on MacOS, Linux will return a defunct process for getpgid. Reaping the processes before checking if one exists resolves this. --- test/test_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 0d86646d..afdd9db5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -86,12 +86,18 @@ def signal_process(pid, signal, wait: nil) end def process_exists?(pid) + reap_processes Process.getpgid(pid) true rescue Errno::ESRCH false end + def reap_processes + Process.waitpid(-1, Process::WNOHANG) + rescue Errno::ECHILD + end + # Allow skipping AR query cache, necessary when running test code in multiple # forks. The queries done in the test might be cached and if we don't perform # any non-SELECT queries after previous SELECT queries were cached on the connection