Skip to content

Commit c22f44b

Browse files
committed
merge revision(s) 44616,44622,44623,44626,44632,44636:
add timeout to test_do_reply http://fb64b.rubyci.org/~chkbuild/ruby-trunk/log/20140115T073301Z.log.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 37095c4 commit c22f44b

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

test/rinda/test_rinda.rb

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require 'drb/eq'
55
require 'rinda/ring'
66
require 'rinda/tuplespace'
7-
7+
require 'timeout'
88
require 'singleton'
99

1010
module Rinda
@@ -559,6 +559,10 @@ def teardown
559559
end
560560

561561
def test_do_reply
562+
with_timeout(10) {_test_do_reply}
563+
end
564+
565+
def _test_do_reply
562566
called = nil
563567

564568
callback = proc { |ts|
@@ -571,12 +575,16 @@ def test_do_reply
571575

572576
@rs.do_reply
573577

574-
Thread.pass until called
578+
wait_for(10) {called}
575579

576580
assert_same @ts, called
577581
end
578582

579583
def test_do_reply_local
584+
with_timeout(10) {_test_do_reply_local}
585+
end
586+
587+
def _test_do_reply_local
580588
called = nil
581589

582590
callback = proc { |ts|
@@ -587,7 +595,7 @@ def test_do_reply_local
587595

588596
@rs.do_reply
589597

590-
Thread.pass until called
598+
wait_for(10) {called}
591599

592600
assert_same @ts, called
593601
end
@@ -674,6 +682,46 @@ def test_shutdown
674682
assert_nil(@rs.do_reply, 'otherwise should hang forever')
675683
end
676684

685+
private
686+
687+
def with_timeout(n)
688+
aoe = Thread.abort_on_exception
689+
Thread.abort_on_exception = true
690+
tl0 = Thread.list
691+
tl = nil
692+
th = Thread.new(Thread.current) do |mth|
693+
sleep n
694+
(tl = Thread.list - tl0).each {|t|t.raise(Timeout::Error)}
695+
mth.raise(Timeout::Error)
696+
end
697+
tl0 << th
698+
rescue Timeout::Error => e
699+
if tl
700+
bt = e.backtrace
701+
tl.each do |t|
702+
begin
703+
t.value
704+
rescue Timeout::Error => e
705+
bt.unshift("")
706+
bt[0, 0] = e.backtrace
707+
end
708+
end
709+
end
710+
raise Timeout::Error, "timeout", bt
711+
ensure
712+
th.kill if th
713+
Thread.abort_on_exception = aoe
714+
end
715+
716+
def wait_for(n)
717+
t = n + Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
718+
until yield
719+
if t < Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
720+
flunk "timeout during waiting call"
721+
end
722+
sleep 0.1
723+
end
724+
end
677725
end
678726

679727
class TestRingFinger < Test::Unit::TestCase

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.1"
2-
#define RUBY_RELEASE_DATE "2014-02-21"
3-
#define RUBY_PATCHLEVEL 47
2+
#define RUBY_RELEASE_DATE "2014-02-22"
3+
#define RUBY_PATCHLEVEL 48
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2
7-
#define RUBY_RELEASE_DAY 21
7+
#define RUBY_RELEASE_DAY 22
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)