From a8b2317d16fa172edd3cd7e6fcb3bc694287d109 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 29 May 2024 10:02:15 -0700 Subject: merge revision(s) 78d9fe69479d32214a52ad7291c3973f1b6b7f6f: [Backport #20286] Ensure that exiting thread invokes end-of-life behaviour. (#10039) --- test/ruby/test_settracefunc.rb | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index dbaf0aaf09..a90c885247 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -2874,4 +2874,52 @@ CODE assert err.kind_of?(RuntimeError) assert_equal err.message.to_i + 3, line end + + def test_tracepoint_thread_begin + target_thread = nil + + trace = TracePoint.new(:thread_begin) do |tp| + target_thread = tp.self + end + + trace.enable(target_thread: nil) do + Thread.new{}.join + end + + assert_kind_of(Thread, target_thread) + end + + def test_tracepoint_thread_end + target_thread = nil + + trace = TracePoint.new(:thread_end) do |tp| + target_thread = tp.self + end + + trace.enable(target_thread: nil) do + Thread.new{}.join + end + + assert_kind_of(Thread, target_thread) + end + + def test_tracepoint_thread_end_with_exception + target_thread = nil + + trace = TracePoint.new(:thread_end) do |tp| + target_thread = tp.self + end + + trace.enable(target_thread: nil) do + thread = Thread.new do + Thread.current.report_on_exception = false + raise + end + + # Ignore the exception raised by the thread: + thread.join rescue nil + end + + assert_kind_of(Thread, target_thread) + end end -- cgit v1.2.3