summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-26 05:13:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-26 05:13:40 +0000
commit72dce44d7b353b0e24324e235ca71d249de18515 (patch)
treefa57d9dc003cea65e123ddfd4ea69b426e1c0a69 /test/ruby
parent501afa013498079ba8d2bd047e86430fe17d2325 (diff)
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
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_backtrace.rb1
-rw-r--r--test/ruby/test_beginendblock.rb5
-rw-r--r--test/ruby/test_proc.rb1
-rw-r--r--test/ruby/test_threadgroup.rb9
4 files changed, 12 insertions, 4 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb
index c4545239a5..0c7677a781 100644
--- a/test/ruby/test_backtrace.rb
+++ b/test/ruby/test_backtrace.rb
@@ -212,6 +212,7 @@ class TestBacktrace < Test::Unit::TestCase
assert_equal(bt, locs)
ensure
q << true
+ th.join
end
end
diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb
index d9c1f56916..a4318493c1 100644
--- a/test/ruby/test_beginendblock.rb
+++ b/test/ruby/test_beginendblock.rb
@@ -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
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 1c8a053cca..284b518121 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -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
diff --git a/test/ruby/test_threadgroup.rb b/test/ruby/test_threadgroup.rb
index e29c477247..f4c03de67e 100644
--- a/test/ruby/test_threadgroup.rb
+++ b/test/ruby/test_threadgroup.rb
@@ -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