[前][次][番号順一覧][スレッド一覧]

ruby-changes:34050

From: nobu <ko1@a...>
Date: Mon, 26 May 2014 14:13:58 +0900 (JST)
Subject: [ruby-changes:34050] nobu:r46131 (trunk): test/ruby: fix leaked threads

nobu	2014-05-26 14:13:40 +0900 (Mon, 26 May 2014)

  New Revision: 46131

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46131

  Log:
    test/ruby: fix leaked threads
    
    * test/thread/test_{backtrace,beginendblock,proc,threadgroup}.rb:
      join work threads not to leak threads.

  Modified files:
    trunk/test/ruby/test_backtrace.rb
    trunk/test/ruby/test_beginendblock.rb
    trunk/test/ruby/test_proc.rb
    trunk/test/ruby/test_threadgroup.rb
Index: test/ruby/test_backtrace.rb
===================================================================
--- test/ruby/test_backtrace.rb	(revision 46130)
+++ test/ruby/test_backtrace.rb	(revision 46131)
@@ -212,6 +212,7 @@ class TestBacktrace < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_backtrace.rb#L212
       assert_equal(bt, locs)
     ensure
       q << true
+      th.join
     end
   end
 
Index: test/ruby/test_threadgroup.rb
===================================================================
--- test/ruby/test_threadgroup.rb	(revision 46130)
+++ test/ruby/test_threadgroup.rb	(revision 46131)
@@ -5,10 +5,13 @@ require_relative 'envutil' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_threadgroup.rb#L5
 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
Index: test/ruby/test_beginendblock.rb
===================================================================
--- test/ruby/test_beginendblock.rb	(revision 46130)
+++ test/ruby/test_beginendblock.rb	(revision 46131)
@@ -127,6 +127,7 @@ EOW https://github.com/ruby/ruby/blob/trunk/test/ruby/test_beginendblock.rb#L127
 
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_beginendblock.rb#L135
        '-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
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 46130)
+++ test/ruby/test_proc.rb	(revision 46131)
@@ -407,6 +407,7 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L407
     t = Thread.new { sleep }
     assert_raise(ThreadError) { t.instance_eval { initialize { } } }
     t.kill
+    t.join
   end
 
   def test_to_proc

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]