mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/ruby: fix leaked threads
* test/thread/test_{backtrace,beginendblock,proc,threadgroup}.rb: join work threads not to leak threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
501afa0134
commit
72dce44d7b
4 changed files with 12 additions and 4 deletions
|
@ -212,6 +212,7 @@ class TestBacktrace < Test::Unit::TestCase
|
|||
assert_equal(bt, locs)
|
||||
ensure
|
||||
q << true
|
||||
th.join
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ EOW
|
|||
|
||||
def test_endblock_raise
|
||||
ruby = EnvUtil.rubybin
|
||||
th = nil
|
||||
out = IO.popen(
|
||||
[ruby,
|
||||
'-e', 'class C; def write(x); puts x; STDOUT.flush; sleep 0.01; end; end',
|
||||
|
@ -134,11 +135,13 @@ EOW
|
|||
'-e', 'END {raise "e1"}; END {puts "e2"}',
|
||||
'-e', 'END {raise "e3"}; END {puts "e4"}',
|
||||
'-e', 'END {raise "e5"}; END {puts "e6"}']) {|f|
|
||||
Thread.new {sleep 5; Process.kill :KILL, f.pid}
|
||||
th = Thread.new {sleep 5; Process.kill :KILL, f.pid}
|
||||
f.read
|
||||
}
|
||||
assert_match(/e1/, out)
|
||||
assert_match(/e6/, out)
|
||||
ensure
|
||||
th.kill if th.alive?
|
||||
end
|
||||
|
||||
def test_nested_at_exit
|
||||
|
|
|
@ -407,6 +407,7 @@ class TestProc < Test::Unit::TestCase
|
|||
t = Thread.new { sleep }
|
||||
assert_raise(ThreadError) { t.instance_eval { initialize { } } }
|
||||
t.kill
|
||||
t.join
|
||||
end
|
||||
|
||||
def test_to_proc
|
||||
|
|
|
@ -5,10 +5,13 @@ require_relative 'envutil'
|
|||
class TestThreadGroup < Test::Unit::TestCase
|
||||
def test_thread_init
|
||||
thgrp = ThreadGroup.new
|
||||
Thread.new{
|
||||
th = Thread.new{
|
||||
thgrp.add(Thread.current)
|
||||
assert_equal(thgrp, Thread.new{sleep 1}.group)
|
||||
}.join
|
||||
Thread.new{sleep 1}
|
||||
}.value
|
||||
assert_equal(thgrp, th.group)
|
||||
ensure
|
||||
th.join
|
||||
end
|
||||
|
||||
def test_frozen_thgroup
|
||||
|
|
Loading…
Reference in a new issue