ruby-changes:34049
From: nobu <ko1@a...>
Date: Mon, 26 May 2014 14:01:45 +0900 (JST)
Subject: [ruby-changes:34049] nobu:r46130 (trunk): test/thread: fix leaked threads
nobu 2014-05-26 14:01:33 +0900 (Mon, 26 May 2014) New Revision: 46130 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46130 Log: test/thread: fix leaked threads * test/thread/test_{queue,sync}.rb: join work threads not to leak threads. Modified files: trunk/test/thread/test_queue.rb trunk/test/thread/test_sync.rb Index: test/thread/test_queue.rb =================================================================== --- test/thread/test_queue.rb (revision 46129) +++ test/thread/test_queue.rb (revision 46130) @@ -62,6 +62,8 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L62 sleep 0.01 until t1.stop? q.max = q.max + 1 assert_equal before + 1, q.max + ensure + t1.join if t1 end def test_queue_pop_interrupt @@ -206,6 +208,13 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_queue.rb#L208 assert_nothing_raised(TimeoutError) do timeout(1) { th2.join } end + ensure + [th1, th2].each do |th| + if th and th.alive? + th.wakeup + th.join + end + end end def test_dup Index: test/thread/test_sync.rb =================================================================== --- test/thread/test_sync.rb (revision 46129) +++ test/thread/test_sync.rb (revision 46130) @@ -19,6 +19,9 @@ class SyncTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_sync.rb#L19 sleep 0.1 until t.stop? assert_equal(tester.sync_waiting.uniq, tester.sync_waiting) + ensure + t.kill + t.join end def test_sync_upgrade_and_wakeup @@ -39,6 +42,9 @@ class SyncTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/thread/test_sync.rb#L42 } assert_equal(tester.sync_waiting.uniq, tester.sync_waiting) assert_equal(tester.sync_waiting, []) + ensure + t.kill + t.join end def test_sync_lock_and_raise -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/