test_rinda.rb: hungup investigation
* test/rinda/test_rinda.rb (with_timeout, wait_for): extract to investigate test_do_reply_local too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ddcb9489e
commit
aef778b4e7
@ -559,17 +559,10 @@ class TestRingServer < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_do_reply
|
def test_do_reply
|
||||||
aoe = Thread.abort_on_exception
|
with_timeout(10) {_test_do_reply}
|
||||||
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
|
end
|
||||||
tl0 << th
|
|
||||||
|
|
||||||
|
def _test_do_reply
|
||||||
called = nil
|
called = nil
|
||||||
|
|
||||||
callback = proc { |ts|
|
callback = proc { |ts|
|
||||||
@ -582,34 +575,16 @@ class TestRingServer < Test::Unit::TestCase
|
|||||||
|
|
||||||
@rs.do_reply
|
@rs.do_reply
|
||||||
|
|
||||||
t = 10 + Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
|
wait_for(10) {called}
|
||||||
until called
|
|
||||||
if t < Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
|
|
||||||
flunk "timeout during waiting call"
|
|
||||||
end
|
|
||||||
sleep 0.1
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_same @ts, 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
|
end
|
||||||
|
|
||||||
def test_do_reply_local
|
def test_do_reply_local
|
||||||
|
with_timeout(10) {_test_do_reply_local}
|
||||||
|
end
|
||||||
|
|
||||||
|
def _test_do_reply_local
|
||||||
called = nil
|
called = nil
|
||||||
|
|
||||||
callback = proc { |ts|
|
callback = proc { |ts|
|
||||||
@ -620,7 +595,7 @@ class TestRingServer < Test::Unit::TestCase
|
|||||||
|
|
||||||
@rs.do_reply
|
@rs.do_reply
|
||||||
|
|
||||||
Thread.pass until called
|
wait_for(10) {called}
|
||||||
|
|
||||||
assert_same @ts, called
|
assert_same @ts, called
|
||||||
end
|
end
|
||||||
@ -707,6 +682,46 @@ class TestRingServer < Test::Unit::TestCase
|
|||||||
assert_nil(@rs.do_reply, 'otherwise should hang forever')
|
assert_nil(@rs.do_reply, 'otherwise should hang forever')
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class TestRingFinger < Test::Unit::TestCase
|
class TestRingFinger < Test::Unit::TestCase
|
||||||
|
Loading…
x
Reference in New Issue
Block a user