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

ruby-changes:32557

From: nobu <ko1@a...>
Date: Sat, 18 Jan 2014 18:38:27 +0900 (JST)
Subject: [ruby-changes:32557] nobu:r44636 (trunk): test_rinda.rb: hungup investigation

nobu	2014-01-18 18:38:22 +0900 (Sat, 18 Jan 2014)

  New Revision: 44636

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

  Log:
    test_rinda.rb: hungup investigation
    
    * test/rinda/test_rinda.rb (with_timeout, wait_for): extract to
      investigate test_do_reply_local too.

  Modified files:
    trunk/test/rinda/test_rinda.rb
Index: test/rinda/test_rinda.rb
===================================================================
--- test/rinda/test_rinda.rb	(revision 44635)
+++ test/rinda/test_rinda.rb	(revision 44636)
@@ -559,17 +559,10 @@ class TestRingServer < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L559
   end
 
   def test_do_reply
-    aoe = Thread.abort_on_exception
-    Thread.abort_on_exception = true
-    tl0 = Thread.list
-    tl = nil
-    th = Thread.new(Thread.current) do |mth|
-      sleep 1
-      (tl = Thread.list - tl0).each {|t|t.raise(Timeout::Error)}
-      mth.raise(Timeout::Error)
-    end
-    tl0 << th
+    with_timeout(10) {_test_do_reply}
+  end
 
+  def _test_do_reply
     called = nil
 
     callback = proc { |ts|
@@ -582,34 +575,16 @@ class TestRingServer < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L575
 
     @rs.do_reply
 
-    t = 10 + Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
-    until called
-      if t < Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
-        flunk "timeout during waiting call"
-      end
-      sleep 0.1
-    end
+    wait_for(10) {called}
 
     assert_same @ts, called
-  rescue Timeout::Error => e
-    if tl
-      bt = e.backtrace
-      tl.each do |t|
-        begin
-          t.value
-        rescue Timeout::Error => e
-          bt.unshift("")
-          bt[0, 0] = e.backtrace
-        end
-      end
-    end
-    raise Timeout::Error, "timeout", bt
-  ensure
-    th.kill if th
-    Thread.abort_on_exception = aoe
   end
 
   def test_do_reply_local
+    with_timeout(10) {_test_do_reply_local}
+  end
+
+  def _test_do_reply_local
     called = nil
 
     callback = proc { |ts|
@@ -620,7 +595,7 @@ class TestRingServer < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L595
 
     @rs.do_reply
 
-    Thread.pass until called
+    wait_for(10) {called}
 
     assert_same @ts, called
   end
@@ -707,6 +682,46 @@ class TestRingServer < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L682
     assert_nil(@rs.do_reply, 'otherwise should hang forever')
   end
 
+  private
+
+  def with_timeout(n)
+    aoe = Thread.abort_on_exception
+    Thread.abort_on_exception = true
+    tl0 = Thread.list
+    tl = nil
+    th = Thread.new(Thread.current) do |mth|
+      sleep n
+      (tl = Thread.list - tl0).each {|t|t.raise(Timeout::Error)}
+      mth.raise(Timeout::Error)
+    end
+    tl0 << th
+  rescue Timeout::Error => e
+    if tl
+      bt = e.backtrace
+      tl.each do |t|
+        begin
+          t.value
+        rescue Timeout::Error => e
+          bt.unshift("")
+          bt[0, 0] = e.backtrace
+        end
+      end
+    end
+    raise Timeout::Error, "timeout", bt
+  ensure
+    th.kill if th
+    Thread.abort_on_exception = aoe
+  end
+
+  def wait_for(n)
+    t = n + Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
+    until yield
+      if t < Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
+        flunk "timeout during waiting call"
+      end
+      sleep 0.1
+    end
+  end
 end
 
 class TestRingFinger < Test::Unit::TestCase

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

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