summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:07:54 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-19 21:07:54 +0000
commit63818379aa3c88681daf634c5f55b2cffac68283 (patch)
treee31b97f96fd519225c7cd4355f636cff1ac9979c /test
parent250fa1cbf04aeea9769be4060825ffcf21f08f91 (diff)
merge revision(s) 56125,56150: [Backport #12741]
* thread.c (rb_threadptr_raise): set cause from the called thread, but not from the thread to be interrupted. [ruby-core:77222] [Bug #12741] * test/ruby/test_exception.rb: fix thread issues. * use Queue instead of a local variable for synchronization. * join created thread to soleve leaking threads warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58026 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_exception.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index cd8743216e..165f679e76 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -703,6 +703,54 @@ end.join
assert_equal('d', e.cause.message, 'cause option should be honored always')
end
+ def test_cause_thread_no_cause
+ bug12741 = '[ruby-core:77222] [Bug #12741]'
+
+ x = Thread.current
+ a = false
+ y = Thread.start do
+ Thread.pass until a
+ x.raise "stop"
+ end
+
+ begin
+ raise bug12741
+ rescue
+ e = assert_raise_with_message(RuntimeError, "stop") do
+ a = true
+ sleep 1
+ end
+ end
+ assert_nil(e.cause)
+ end
+
+ def test_cause_thread_with_cause
+ bug12741 = '[ruby-core:77222] [Bug #12741]'
+
+ x = Thread.current
+ q = Queue.new
+ y = Thread.start do
+ q.pop
+ begin
+ raise "caller's cause"
+ rescue
+ x.raise "stop"
+ end
+ end
+
+ begin
+ raise bug12741
+ rescue
+ e = assert_raise_with_message(RuntimeError, "stop") do
+ q.push(true)
+ sleep 1
+ end
+ ensure
+ y.join
+ end
+ assert_equal("caller's cause", e.cause.message)
+ end
+
def test_unknown_option
bug = '[ruby-core:63203] [Feature #8257] should pass unknown options'