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

ruby-changes:51673

From: normal <ko1@a...>
Date: Sun, 8 Jul 2018 16:27:33 +0900 (JST)
Subject: [ruby-changes:51673] normal:r63885 (trunk): test/ruby (*no_hidden_garbage): disable GC and skip if multi-threaded

normal	2018-07-08 16:27:29 +0900 (Sun, 08 Jul 2018)

  New Revision: 63885

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

  Log:
    test/ruby (*no_hidden_garbage): disable GC and skip if multi-threaded
    
    Any single object allocation can reduce object count, and
    object counts are global, so multi-threading leads to unpredictable
    results.
    
    See also similar commits: r60699 and r62608

  Modified files:
    trunk/test/ruby/test_sprintf.rb
    trunk/test/ruby/test_time.rb
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 63884)
+++ test/ruby/test_time.rb	(revision 63885)
@@ -1109,11 +1109,14 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L1109
     fmt = %w(Y m d).map { |x| "%#{x}" }.join('-') # defeats optimization
     t = Time.at(0).getutc
     ObjectSpace.count_objects(res = {}) # creates strings on first call
+    GC.disable
     before = ObjectSpace.count_objects(res)[:T_STRING]
     val = t.strftime(fmt)
     after = ObjectSpace.count_objects(res)[:T_STRING]
     assert_equal before + 1, after, 'only new string is the created one'
     assert_equal '1970-01-01', val
+  ensure
+    GC.enable
   end
 
   def test_num_exact_error
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 63884)
+++ test/ruby/test_sprintf.rb	(revision 63885)
@@ -524,12 +524,17 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_sprintf.rb#L524
   end
 
   def test_no_hidden_garbage
+    skip unless Thread.list.size == 1
+
     fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
     ObjectSpace.count_objects(res = {}) # creates strings on first call
+    GC.disable
     before = ObjectSpace.count_objects(res)[:T_STRING]
     val = sprintf(fmt, 1970, 1, 1)
     after = ObjectSpace.count_objects(res)[:T_STRING]
     assert_equal before + 1, after, 'only new string is the created one'
     assert_equal '1970-01-01', val
+  ensure
+    GC.enable
   end
 end

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

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