diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-10 13:05:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-10 13:05:53 +0000 |
commit | c15d95708f1fb5628f3eef5152e0828328b1cd6c (patch) | |
tree | c03cca1e3b71be938e56cdf824b7d3a7fac040c1 | |
parent | 7f32234e3e4c46df37983df7f21e8944e07a5e4a (diff) | |
download | ruby-c15d95708f1fb5628f3eef5152e0828328b1cd6c.tar.gz |
timeout.rb: removed and use Timeout::Error
* lib/timeout.rb (ExitException): removed internal exception class
and use Timeout::Error instead, as using throw/catch to isolate
each timeouts now. [ruby-dev:49179] [Bug #11344]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/timeout.rb | 4 | ||||
-rw-r--r-- | test/test_timeout.rb | 23 |
3 files changed, 27 insertions, 6 deletions
@@ -1,3 +1,9 @@ +Fri Jul 10 22:05:50 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/timeout.rb (ExitException): removed internal exception class + and use Timeout::Error instead, as using throw/catch to isolate + each timeouts now. [ruby-dev:49179] [Bug #11344] + Fri Jul 10 20:13:05 2015 Naohisa Goto <ngotogenome@gmail.com> * process.c (rb_f_exec): rb_exec_without_timer_thread should be diff --git a/lib/timeout.rb b/lib/timeout.rb index fec7b9428c..b57a11384f 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -24,8 +24,6 @@ module Timeout # Raised by Timeout#timeout when the block times out. class Error < RuntimeError - end - class ExitException < ::Exception # :nodoc: attr_reader :thread def self.catch(*args) @@ -101,7 +99,7 @@ module Timeout bt = e.backtrace end else - bt = ExitException.catch(message, &bl) + bt = Error.catch(message, &bl) end rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o bt.reject! {|m| rej =~ m} diff --git a/test/test_timeout.rb b/test/test_timeout.rb index e71a09f22c..e4eba7f902 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -63,9 +63,9 @@ class TestTimeout < Test::Unit::TestCase end def test_exit_exception - assert_raise_with_message(Timeout::ExitException, "boon") do - Timeout.timeout(10, Timeout::ExitException) do - raise Timeout::ExitException, "boon" + assert_raise_with_message(Timeout::Error, "boon") do + Timeout.timeout(10, Timeout::Error) do + raise Timeout::Error, "boon" end end end @@ -80,4 +80,21 @@ class TestTimeout < Test::Unit::TestCase Timeout.timeout(0.01) {e.next} end end + + def test_handle_interrupt + bug11344 = '[ruby-dev:49179] [Bug #11344]' + ok = false + assert_raise(Timeout::Error) { + Thread.handle_interrupt(Timeout::Error => :never) { + Timeout.timeout(0.01) { + sleep 0.2 + ok = true + Thread.handle_interrupt(Timeout::Error => :on_blocking) { + sleep 0.2 + } + } + } + } + assert(ok, bug11344) + end end |