summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-05 12:43:19 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-05 12:43:19 +0000
commitc00e288936dbcfcaa3b9eaadbd14ab94f778389e (patch)
tree03ed3d6676ce0500d7e58244ab560a54cea796e8 /test
parentc0bdb2511d898cb875e75dc1e7f774112e5341f9 (diff)
merge revision(s) 44517,44518,44519,44523: [Backport #9354]
* lib/timeout.rb (Timeout#timeout): when a custom exception is given, no instance is needed to be caught, so defer creating new instance until it is raised. [ruby-core:59511] [Bug #9354] * lib/timeout.rb (Timeout#timeout): should not rescue ordinarily raised ExitException, which should not be thrown. * lib/timeout.rb (Timeout::ExitException.catch): set @thread only if it ought to be caught. * lib/timeout.rb (Timeout::ExitException.catch): pass arguments for new instance. * lib/timeout.rb (Timeout::ExitException#exception): fallback to Timeout::Error if couldn't throw. [ruby-dev:47872] [Bug #9380] * lib/timeout.rb (Timeout#timeout): initialize ExitException with message for the fallback case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@44841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_timeout.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_timeout.rb b/test/test_timeout.rb
index 9d51ca5be3..e849cc5741 100644
--- a/test/test_timeout.rb
+++ b/test/test_timeout.rb
@@ -57,4 +57,33 @@ class TestTimeout < Test::Unit::TestCase
end
assert_raise_with_message(exc, /execution expired/) {raise e if e}
end
+
+ def test_custom_exception
+ bug9354 = '[ruby-core:59511] [Bug #9354]'
+ err = Class.new(StandardError) do
+ def initialize(msg) super end
+ end
+ assert_nothing_raised(ArgumentError, bug9354) do
+ assert_equal(:ok, timeout(100, err) {:ok})
+ end
+ end
+
+ def test_exit_exception
+ assert_raise_with_message(Timeout::ExitException, "boon") do
+ Timeout.timeout(10, Timeout::ExitException) do
+ raise Timeout::ExitException, "boon"
+ end
+ end
+ end
+
+ def test_enumerator_next
+ bug9380 = '[ruby-dev:47872] [Bug #9380]: timeout in Enumerator#next'
+ e = (o=Object.new).to_enum
+ def o.each
+ sleep
+ end
+ assert_raise_with_message(Timeout::Error, 'execution expired', bug9380) do
+ Timeout.timeout(0.01) {e.next}
+ end
+ end
end