From c5eb414a94c44ace1adccc1eae4b01eb13fe1b13 Mon Sep 17 00:00:00 2001 From: Louis-Michel Couture Date: Fri, 1 Mar 2024 15:24:21 -0500 Subject: [PATCH] Make sure no error is raised when a process is already terminated --- lib/parallel_tests.rb | 2 ++ spec/parallel_tests_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/parallel_tests.rb b/lib/parallel_tests.rb index 356ba7ef..48e9c94e 100644 --- a/lib/parallel_tests.rb +++ b/lib/parallel_tests.rb @@ -44,6 +44,8 @@ def pid_file_path def stop_all_processes pids.all.each { |pid| Process.kill(:INT, pid) } + rescue Errno::ESRCH + # Process already terminated, do nothing end # copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile diff --git a/spec/parallel_tests_spec.rb b/spec/parallel_tests_spec.rb index fe87e435..bed4b9b6 100644 --- a/spec/parallel_tests_spec.rb +++ b/spec/parallel_tests_spec.rb @@ -194,6 +194,13 @@ def with_running_processes(count, wait = 0.2) expect(ParallelTests.pids.count).to eq(0) end end + + it "doesn't fail if the pid has already been killed", unless: Gem.win_platform? do + ParallelTests.with_pid_file do + ParallelTests.pids.add(1234) + expect { ParallelTests.stop_all_processes }.not_to raise_error + end + end end it "has a version" do