diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-06 00:25:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-06 00:25:38 +0000 |
commit | e18ee39c35b3e9ed77ddef7f49d5e502dc18fd8e (patch) | |
tree | d67ef654e4907461ec2c28466f8761a96c3431d3 /test/ruby/test_thread.rb | |
parent | cf23b8c4dec42f1779309241f7d0f70b599327d8 (diff) | |
download | ruby-e18ee39c35b3e9ed77ddef7f49d5e502dc18fd8e.tar.gz |
Thread.report_on_exception
* thread.c (thread_start_func_2): report raised exception if
report_on_exception flag is set. [Feature #6647]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_thread.rb')
-rw-r--r-- | test/ruby/test_thread.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index f13a962c9b..c977d17ecc 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -344,6 +344,62 @@ class TestThread < Test::Unit::TestCase INPUT end + def test_report_on_exception + assert_separately([], <<~"end;") #do + q1 = Queue.new + q2 = Queue.new + + assert_equal(false, Thread.report_on_exception, + "global flags is false by default") + assert_equal(false, Thread.current.report_on_exception) + + Thread.current.report_on_exception = true + assert_equal(false, + Thread.start {Thread.current.report_on_exception}.value, + "should not inherit from the parent thread") + + assert_warn("", "exception should be ignored silently") { + th = Thread.start { + q1.push(Thread.current.report_on_exception) + raise "report 1" + } + assert_equal(false, q1.pop) + Thread.pass while th.alive? + } + + assert_warn(/report 2/, "exception should be reported") { + th = Thread.start { + q1.push(Thread.current.report_on_exception = true) + raise "report 2" + } + assert_equal(true, q1.pop) + Thread.pass while th.alive? + } + + assert_equal(false, Thread.report_on_exception) + assert_warn("", "the global flag should not affect already started threads") { + th = Thread.start { + q2.pop + q1.push(Thread.current.report_on_exception) + raise "report 3" + } + q2.push(Thread.report_on_exception = true) + assert_equal(false, q1.pop) + Thread.pass while th.alive? + } + + assert_equal(true, Thread.report_on_exception) + assert_warn(/report 4/, "should defaults to the global flag at the start") { + th = Thread.start { + q1.push(Thread.current.report_on_exception) + raise "report 4" + } + assert_equal(true, q1.pop) + Thread.pass while th.alive? + } + end; + end + def test_status_and_stop_p a = ::Thread.new { raise("die now") } b = Thread.new { Thread.stop } |