[前][次][番号順一覧][スレッド一覧]

ruby-changes:32610

From: nobu <ko1@a...>
Date: Thu, 23 Jan 2014 18:15:53 +0900 (JST)
Subject: [ruby-changes:32610] nobu:r44689 (trunk): test_process.rb: deadlock test

nobu	2014-01-23 18:15:47 +0900 (Thu, 23 Jan 2014)

  New Revision: 44689

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44689

  Log:
    test_process.rb: deadlock test
    
    * test/ruby/test_process.rb (test_deadlock_by_signal_at_forking): test
      for r44687, deadlock in rb_fork_internal().

  Modified files:
    trunk/test/ruby/test_process.rb
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 44688)
+++ test/ruby/test_process.rb	(revision 44689)
@@ -1860,4 +1860,52 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1860
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]