summaryrefslogtreecommitdiff
path: root/bootstraptest/test_fork.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bootstraptest/test_fork.rb')
-rw-r--r--bootstraptest/test_fork.rb27
1 files changed, 16 insertions, 11 deletions
diff --git a/bootstraptest/test_fork.rb b/bootstraptest/test_fork.rb
index 3842947..91281a3 100644
--- a/bootstraptest/test_fork.rb
+++ b/bootstraptest/test_fork.rb
@@ -22,26 +22,32 @@ assert_finish 10, %q{
}, '[ruby-core:22158]'
assert_normal_exit(<<'End', '[ruby-dev:37934]')
- Thread.new { sleep 1; Thread.kill Thread.main }
+ main = Thread.current
+ Thread.new { sleep 0.01 until main.stop?; Thread.kill main }
Process.setrlimit(:NPROC, 1)
fork {}
End
assert_equal 'ok', %q{
begin
+ r, w = IO.pipe
if pid1 = fork
- sleep 1
+ w.close
+ r.read(1)
Process.kill("USR1", pid1)
_, s = Process.wait2(pid1)
s.success? ? :ok : :ng
else
+ r.close
if pid2 = fork
- trap("USR1") { Time.now.to_s }
+ trap("USR1") { Time.now.to_s; Process.kill("USR2", pid2) }
+ w.close
Process.wait2(pid2)
else
- sleep 2
+ w.close
+ sleep 0.2
end
- exit 0
+ exit true
end
rescue NotImplementedError
:ok
@@ -50,17 +56,16 @@ assert_equal 'ok', %q{
assert_equal '[1, 2]', %q{
a = []
- trap(:INT) { a.push(1) }
- trap(:TERM) { a.push(2) }
+ main = Thread.current
+ trap(:INT) { a.push(1).size == 2 and main.wakeup }
+ trap(:TERM) { a.push(2).size == 2 and main.wakeup }
pid = $$
begin
- fork do
- sleep 0.5
+ pid = fork do
Process.kill(:INT, pid)
Process.kill(:TERM, pid)
end
-
- sleep 1
+ Process.wait(pid)
a.sort
rescue NotImplementedError
[1, 2]