Skip to content

Commit

Permalink
Reap processes before checking for them
Browse files Browse the repository at this point in the history
Unlike on MacOS, Linux will return a defunct process for getpgid.
Reaping the processes before checking if one exists resolves this.
  • Loading branch information
djmb committed Oct 11, 2023
1 parent 7666618 commit 2e76576
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e76576

Please sign in to comment.