Fix race condition in test_self_stop

This test was relying on a sleep to synchronise the parent and child
processes. By having the child be the process that stops itself with
SIGSTOP, instead of the parent, we can actually properly wait for that
using waitpid2 and be notified of the stop.

This use of sleep to synchronise processes is potentially flaky and
caused failures under rr's `--chaos` mode.
This commit is contained in:
KJ Tsanaktsidis 2024-11-09 15:26:53 +11:00
parent c8c94bfb1e
commit 2694585fb3
Notes: git 2024-11-09 05:13:34 +00:00

View File

@ -310,17 +310,25 @@ class TestSignal < Test::Unit::TestCase
end end
def test_self_stop def test_self_stop
assert_ruby_status([], <<-'end;') omit unless Process.respond_to?(:fork)
begin omit unless defined?(Process::WUNTRACED)
fork{
sleep 1 # Make a process that stops itself
Process.kill(:CONT, Process.ppid) child_pid = fork do
} Process.kill(:STOP, Process.pid)
Process.kill(:STOP, Process.pid) end
rescue NotImplementedError
# ok # The parent should be notified about the stop
end _, status = Process.waitpid2(child_pid, Process::WUNTRACED)
end; assert status.stopped?
# It can be continued
Process.kill(:CONT, child_pid)
# And the child then runs to completion
_, status = Process.waitpid2(child_pid)
assert status.exited?
assert status.success?
end end
def test_sigwait_fd_unused def test_sigwait_fd_unused