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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c93adfc170
commit
d41baaee9f
@ -524,12 +524,17 @@ class TestSprintf < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_no_hidden_garbage
|
def test_no_hidden_garbage
|
||||||
|
skip unless Thread.list.size == 1
|
||||||
|
|
||||||
fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
|
fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
|
||||||
ObjectSpace.count_objects(res = {}) # creates strings on first call
|
ObjectSpace.count_objects(res = {}) # creates strings on first call
|
||||||
|
GC.disable
|
||||||
before = ObjectSpace.count_objects(res)[:T_STRING]
|
before = ObjectSpace.count_objects(res)[:T_STRING]
|
||||||
val = sprintf(fmt, 1970, 1, 1)
|
val = sprintf(fmt, 1970, 1, 1)
|
||||||
after = ObjectSpace.count_objects(res)[:T_STRING]
|
after = ObjectSpace.count_objects(res)[:T_STRING]
|
||||||
assert_equal before + 1, after, 'only new string is the created one'
|
assert_equal before + 1, after, 'only new string is the created one'
|
||||||
assert_equal '1970-01-01', val
|
assert_equal '1970-01-01', val
|
||||||
|
ensure
|
||||||
|
GC.enable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1109,11 +1109,14 @@ class TestTime < Test::Unit::TestCase
|
|||||||
fmt = %w(Y m d).map { |x| "%#{x}" }.join('-') # defeats optimization
|
fmt = %w(Y m d).map { |x| "%#{x}" }.join('-') # defeats optimization
|
||||||
t = Time.at(0).getutc
|
t = Time.at(0).getutc
|
||||||
ObjectSpace.count_objects(res = {}) # creates strings on first call
|
ObjectSpace.count_objects(res = {}) # creates strings on first call
|
||||||
|
GC.disable
|
||||||
before = ObjectSpace.count_objects(res)[:T_STRING]
|
before = ObjectSpace.count_objects(res)[:T_STRING]
|
||||||
val = t.strftime(fmt)
|
val = t.strftime(fmt)
|
||||||
after = ObjectSpace.count_objects(res)[:T_STRING]
|
after = ObjectSpace.count_objects(res)[:T_STRING]
|
||||||
assert_equal before + 1, after, 'only new string is the created one'
|
assert_equal before + 1, after, 'only new string is the created one'
|
||||||
assert_equal '1970-01-01', val
|
assert_equal '1970-01-01', val
|
||||||
|
ensure
|
||||||
|
GC.enable
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_num_exact_error
|
def test_num_exact_error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user