diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_backtrace.rb | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb index cfdbd72d9f..ebbde9f060 100644 --- a/test/ruby/test_backtrace.rb +++ b/test/ruby/test_backtrace.rb @@ -1,5 +1,5 @@ - require 'test/unit' +require 'thread' class TestBacktrace < Test::Unit::TestCase def test_exception @@ -91,4 +91,39 @@ class TestBacktrace < Test::Unit::TestCase } assert_equal(cs, locs) end + + def th_rec q, n=10 + if n > 1 + th_rec q, n-1 + else + q.pop + end + end + + def test_thread_backtrace + begin + q = Queue.new + th = Thread.new{ + th_rec q + } + sleep 0.5 + th_backtrace = th.backtrace + th_locations = th.backtrace_locations + + assert_equal(10, th_backtrace.count{|e| e =~ /th_rec/}) + assert_equal(th_backtrace, th_locations.map{|e| e.to_s}) + assert_equal(th_backtrace, th.backtrace(0)) + assert_equal(th_locations.map{|e| e.to_s}, + th.backtrace_locations(0).map{|e| e.to_s}) + th_backtrace.size.times{|n| + assert_equal(n, th.backtrace(0, n).size) + assert_equal(n, th.backtrace_locations(0, n).size) + } + n = th_backtrace.size + assert_equal(n, th.backtrace(0, n + 1).size) + assert_equal(n, th.backtrace_locations(0, n + 1).size) + ensure + q << true + end + end end |