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

ruby-changes:52449

From: normal <ko1@a...>
Date: Sat, 8 Sep 2018 10:09:49 +0900 (JST)
Subject: [ruby-changes:52449] normal:r64658 (trunk): test/ruby/test_thread.rb: join threads in each test

normal	2018-09-08 10:09:44 +0900 (Sat, 08 Sep 2018)

  New Revision: 64658

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64658

  Log:
    test/ruby/test_thread.rb: join threads in each test
    
    Leaky thread detection doesn't happen frequently, enough

  Modified files:
    trunk/test/ruby/test_thread.rb
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 64657)
+++ test/ruby/test_thread.rb	(revision 64658)
@@ -168,6 +168,8 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L168
     t1.kill
     t2.kill
     assert_operator(c1, :>, c2, "[ruby-dev:33124]") # not guaranteed
+    t1.join
+    t2.join
   end
 
   def test_new
@@ -186,8 +188,8 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L188
     end
 
   ensure
-    t1.kill if t1
-    t2.kill if t2
+    t1&.kill.join
+    t2&.kill.join
   end
 
   def test_new_symbol_proc
@@ -203,7 +205,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L205
     assert_nil(t.join(0.05))
 
   ensure
-    t.kill if t
+    t&.kill.join
   end
 
   def test_join2
@@ -309,9 +311,8 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L311
     Thread.pass while t.alive?
     assert_equal(2, s)
     assert_raise(ThreadError) { t.wakeup }
-
   ensure
-    t.kill if t
+    t&.kill.join
   end
 
   def test_stop
@@ -432,6 +433,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L433
         }
         assert_equal(false, q1.pop)
         Thread.pass while th.alive?
+        assert_raise(RuntimeError) { th.join }
       }
 
       assert_warn(/report 2/, "exception should be reported when true") {
@@ -441,6 +443,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L443
         }
         assert_equal(true, q1.pop)
         Thread.pass while th.alive?
+        assert_raise(RuntimeError) { th.join }
       }
 
       assert_warn("", "the global flag should not affect already started threads") {
@@ -453,6 +456,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L456
         q2.push(Thread.report_on_exception = true)
         assert_equal(false, q1.pop)
         Thread.pass while th.alive?
+        assert_raise(RuntimeError) { th.join }
       }
 
       assert_warn(/report 4/, "should defaults to the global flag at the start") {
@@ -463,6 +467,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L467
         }
         assert_equal(true, q1.pop)
         Thread.pass while th.alive?
+        assert_raise(RuntimeError) { th.join }
       }
 
       assert_warn(/report 5/, "should first report and then raise with report_on_exception + abort_on_exception") {
@@ -476,6 +481,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L481
           q2.push(true)
           Thread.pass while th.alive?
         }
+        assert_raise(RuntimeError) { th.join }
       }
     end;
   end
@@ -503,11 +509,10 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L509
     es1 = e.status
     es2 = e.stop?
     assert_equal(["run", false], [es1, es2])
-
+    assert_raise(RuntimeError) { a.join }
   ensure
-    a.kill if a
-    b.kill if b
-    c.kill if c
+    b&.kill.join
+    c&.join
   end
 
   def test_switch_while_busy_loop
@@ -542,7 +547,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L547
     assert_equal($SAFE, t.safe_level)
   ensure
     $SAFE = 0
-    t.kill if t
+    t&.kill.join
   end
 
   def test_thread_local
@@ -562,7 +567,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L567
     assert_equal([:foo, :bar, :baz].sort, t.keys.sort)
 
   ensure
-    t.kill if t
+    t&.kill.join
   end
 
   def test_thread_local_fetch
@@ -594,7 +599,7 @@ class TestThread < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L599
     assert_equal(:qux, e.key)
     assert_equal(t, e.receiver)
   ensure
-    t.kill if t
+    t&.kill.join
   end
 
   def test_thread_local_security

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

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