mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
d89e8fb53a
commit
c8a7730c7d
1 changed files with 48 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue