summaryrefslogtreecommitdiff
path: root/test/ruby/test_process.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-23 09:15:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-23 09:15:47 +0000
commitc8a7730c7d8e948147059f0ac7c9268fb03c53bc (patch)
tree04eb5db14a5b92e12502a3e821c4d8eabd88d95a /test/ruby/test_process.rb
parentd89e8fb53a01b9d997145c9723bd949b36f3c1a2 (diff)
test_process.rb: deadlock test
* test/ruby/test_process.rb (test_deadlock_by_signal_at_forking): test for r44687, deadlock in rb_fork_internal(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_process.rb')
-rw-r--r--test/ruby/test_process.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index c77cbabee8..8302539734 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1860,4 +1860,52 @@ EOS
assert_kind_of(Float, t, "Process.clock_getres(:#{n})")
end
+ def test_deadlock_by_signal_at_forking
+ ruby = EnvUtil.rubybin
+ er, ew = IO.pipe
+ unless runner = IO.popen("-")
+ er.close
+ begin
+ $stderr.reopen($stdout)
+ trap(:QUIT) {}
+ 100.times do |i|
+ pid = fork {Process.kill(:QUIT, Process.ppid)}
+ IO.popen(ruby, 'r+'){}
+ Process.wait(pid)
+ $stdout.puts
+ $stdout.flush
+ end
+ ensure
+ ew.puts([Marshal.dump($!)].pack("m0")) if $!
+ ew.close
+ end
+ exit!(true)
+ end
+ ew.close
+ begin
+ loop do
+ Timeout.timeout(5) do
+ runner.readpartial(100)
+ end
+ end
+ rescue EOFError => e
+ _, status = Process.wait2(runner.pid)
+ rescue Timeout::Error => e
+ Process.kill(:INT, runner.pid)
+ raise Marshal.load(er.read.unpack("m")[0])
+ end
+ assert_predicate(status, :success?)
+ ensure
+ er.close unless er.closed?
+ ew.close unless ew.closed?
+ if runner
+ begin
+ Process.kill(:TERM, runner.pid)
+ sleep 1
+ Process.kill(:KILL, runner.pid)
+ rescue Errno::ESRCH
+ end
+ runner.close
+ end
+ end if defined?(Process.fork)
end