summaryrefslogtreecommitdiff
path: root/test/ruby/test_process.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_process.rb')
-rw-r--r--test/ruby/test_process.rb30
1 files changed, 27 insertions, 3 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 1228f2c0b1..8e1c3a0d47 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2659,7 +2659,7 @@ EOS
end;
end if Process.respond_to?(:_fork)
- def test_concurrent_group_and_pid_wait
+ def _test_concurrent_group_and_pid_wait(nohang)
# Use a pair of pipes that will make long_pid exit when this test exits, to avoid
# leaking temp processes.
long_rpipe, long_wpipe = IO.pipe
@@ -2681,10 +2681,26 @@ EOS
end
# Wait for us to be blocking in a call to waitpid2
Thread.pass until t1.stop?
+ assert_nil Process.waitpid(-1, Process::WNOHANG)
short_wpipe.close # Make short_pid exit
- # The short pid has exited, so -1 should pick that up.
- assert_equal short_pid, Process.waitpid(-1)
+ # The short pid has exited, so waitpid(-1) should pick that up.
+ exited_pid =
+ unless nohang
+ Process.waitpid(-1)
+ else
+ EnvUtil.timeout(5) do
+ loop do
+ pid = Process.waitpid(-1, Process::WNOHANG)
+
+ break pid if pid
+
+ sleep 0.1
+ end
+ end
+ end
+
+ assert_equal short_pid, exited_pid
# Terminate t1 for the next phase of the test.
t1.kill
@@ -2714,6 +2730,14 @@ EOS
[long_rpipe, long_wpipe, short_rpipe, short_wpipe].each { _1&.close rescue nil }
end if defined?(fork)
+ def test_concurrent_group_and_pid_wait
+ _test_concurrent_group_and_pid_wait(false)
+ end if defined?(fork)
+
+ def test_concurrent_group_and_pid_wait_nohang
+ _test_concurrent_group_and_pid_wait(true)
+ end if defined?(fork)
+
def test_handle_interrupt_with_fork
Thread.handle_interrupt(RuntimeError => :never) do
Thread.current.raise(RuntimeError, "Queued error")