mirror of
https://github.com/ruby/ruby.git
synced 2026-08-02 20:49:12 +08:00
show loadavg if the test fails
to survey the following failure: ``` 1) Failure: TestFile#test_stat [/tmp/ruby/src/trunk-repeat20/test/ruby/test_file.rb:412]: Expected |1770056232.744032 - 1770056230.6465776| (2.097454309463501) to be <= 1. ``` BTW I found that `test/ruby/test_file.rb:412` `assert_in_delta atime, stat.atime.to_f, delta` only fails (mtime, ctime doesn't fail on 100 days).
This commit is contained in:
parent
2dc4e872e8
commit
2ba2950d20
Notes:
git
2026-06-24 05:44:20 +00:00
@ -128,8 +128,16 @@ module Test
|
||||
|
||||
def assert_in_delta exp, act, delta = 0.001, msg = nil
|
||||
n = (exp - act).abs
|
||||
loadavg = begin
|
||||
if File.readable?("/proc/loadavg")
|
||||
" (/proc/loadavg=#{File.read("/proc/loadavg").strip})"
|
||||
end
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
loadavg ||= ""
|
||||
msg = message(msg) {
|
||||
"Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
|
||||
"Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}#{loadavg}"
|
||||
}
|
||||
assert delta >= n, msg
|
||||
end
|
||||
|
||||
@ -646,7 +646,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase
|
||||
|
||||
def test_assert_in_delta_triggered
|
||||
x = "1.0e-06"
|
||||
util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
||||
util_assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}.", strip: /\s+\(\/proc\/loadavg=.*\)/ do
|
||||
@tc.assert_in_delta 0.0, 1.0 / 1000, 0.000001
|
||||
end
|
||||
end
|
||||
@ -678,7 +678,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_assert_in_epsilon_triggered
|
||||
util_assert_triggered 'Expected |10000 - 9990| (10) to be <= 9.99.' do
|
||||
util_assert_triggered 'Expected |10000 - 9990| (10) to be <= 9.99.', strip: /\s+\(\/proc\/loadavg=.*\)/ do
|
||||
@tc.assert_in_epsilon 10000, 9990
|
||||
end
|
||||
end
|
||||
@ -686,7 +686,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase
|
||||
def test_assert_in_epsilon_triggered_negative_case
|
||||
x = "0.100000xxx"
|
||||
y = "0.1"
|
||||
util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}." do
|
||||
util_assert_triggered "Expected |-1.1 - -1| (#{x}) to be <= #{y}.", strip: /\s+\(\/proc\/loadavg=.*\)/ do
|
||||
@tc.assert_in_epsilon(-1.1, -1, 0.1)
|
||||
end
|
||||
end
|
||||
@ -1352,7 +1352,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase
|
||||
assert_equal expected, sample_test_case.test_methods.sort
|
||||
end
|
||||
|
||||
def assert_triggered expected, klass = Test::Unit::AssertionFailedError
|
||||
def assert_triggered expected, klass = Test::Unit::AssertionFailedError, strip: nil
|
||||
e = assert_raise klass do
|
||||
yield
|
||||
end
|
||||
@ -1360,6 +1360,7 @@ class TestMiniTestUnitTestCase < Test::Unit::TestCase
|
||||
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
||||
msg.gsub!(/\(oid=[-0-9]+\)/, '(oid=N)')
|
||||
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
||||
msg.gsub!(strip, '') if strip
|
||||
|
||||
assert_equal expected, msg
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user