summaryrefslogtreecommitdiff
path: root/jni/ruby/bootstraptest/test_fork.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/bootstraptest/test_fork.rb
Fresh start
Diffstat (limited to 'jni/ruby/bootstraptest/test_fork.rb')
-rw-r--r--jni/ruby/bootstraptest/test_fork.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/jni/ruby/bootstraptest/test_fork.rb b/jni/ruby/bootstraptest/test_fork.rb
new file mode 100644
index 0000000..5de6ee1
--- /dev/null
+++ b/jni/ruby/bootstraptest/test_fork.rb
@@ -0,0 +1,75 @@
+assert_equal '0', %q{
+ begin
+ GC.stress = true
+ pid = fork {}
+ Process.wait pid
+ $?.to_i
+ rescue NotImplementedError
+ 0
+ end
+}, '[ruby-dev:32404]'
+
+assert_finish 10, %q{
+ begin
+ children = (1..10).map{
+ Thread.start{fork{}}.value
+ }
+ while !children.empty? and pid = Process.wait
+ children.delete(pid)
+ end
+ rescue NotImplementedError
+ end
+}, '[ruby-core:22158]'
+
+assert_normal_exit(<<'End', '[ruby-dev:37934]')
+ 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
+ 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; Process.kill("USR2", pid2) }
+ w.close
+ Process.wait2(pid2)
+ else
+ w.close
+ sleep 0.2
+ end
+ exit true
+ end
+ rescue NotImplementedError
+ :ok
+ end
+}, '[ruby-core:28924]'
+
+assert_equal '[1, 2]', %q{
+ a = []
+ 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
+ pid = fork do
+ Process.kill(:INT, pid)
+ Process.kill(:TERM, pid)
+ end
+ Process.wait(pid)
+ 100.times {break if a.size > 1; sleep 0.001}
+ a.sort
+ rescue NotImplementedError
+ [1, 2]
+ end
+}, '[ruby-dev:44005] [Ruby 1.9 - Bug #4950]'
+