From 2e71c752787e0c7659bd5e89b6c5d433eddfe13a Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 6 Jun 2016 00:25:38 +0000 Subject: 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 --- test/ruby/test_thread.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test/ruby') 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 } -- cgit v1.2.3