summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorKJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>2024-11-09 15:26:53 +1100
committerKJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>2024-11-08 22:13:15 -0700
commit2694585fb38fcb2becaa7c65d8a1ec0b0b320b9b (patch)
tree85b6f07137d9b9763b64771d758a45e93f72b43a /test/ruby
parentc8c94bfb1edd6e1e045d503dfba9a96077306a27 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12042
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_signal.rb30
1 files changed, 19 insertions, 11 deletions
diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb
index 7877a35129..a2bdf02b88 100644
--- a/test/ruby/test_signal.rb
+++ b/test/ruby/test_signal.rb
@@ -310,17 +310,25 @@ class TestSignal < Test::Unit::TestCase
end
def test_self_stop
- assert_ruby_status([], <<-'end;')
- begin
- fork{
- sleep 1
- Process.kill(:CONT, Process.ppid)
- }
- Process.kill(:STOP, Process.pid)
- rescue NotImplementedError
- # ok
- end
- end;
+ omit unless Process.respond_to?(:fork)
+ omit unless defined?(Process::WUNTRACED)
+
+ # Make a process that stops itself
+ child_pid = fork do
+ Process.kill(:STOP, Process.pid)
+ end
+
+ # The parent should be notified about the stop
+ _, status = Process.waitpid2(child_pid, Process::WUNTRACED)
+ 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
def test_sigwait_fd_unused