diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2019-12-01 23:23:40 -0800 |
---|---|---|
committer | Takashi Kokubun <takashikkbn@gmail.com> | 2019-12-01 23:23:40 -0800 |
commit | 185f7608737a550a0891a7fc5a6a4ee32721bce3 (patch) | |
tree | 3f02b90be6f6ec26e60fe66d7faa556a371baaf8 /spec/ruby/core | |
parent | 9afaf139f232e8b2c697d33e984945464744def1 (diff) | |
download | ruby-185f7608737a550a0891a7fc5a6a4ee32721bce3.tar.gz |
Debug random failure of ruby-spec on ci.rvm.jp
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/process/times_spec.rb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb index 32a566609d..510ea899b9 100644 --- a/spec/ruby/core/process/times_spec.rb +++ b/spec/ruby/core/process/times_spec.rb @@ -16,14 +16,42 @@ describe "Process.times" do ruby_version_is "2.5" do platform_is_not :windows do it "uses getrusage when available to improve precision beyond milliseconds" do - times = 100.times.map { Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) } - if times.count { |t| ((t * 1e6).to_i % 1000) > 0 } == 0 + gettimes = 100.times.map { Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) } + if gettimes.count { |t| ((t * 1e6).to_i % 1000) > 0 } == 0 skip "getrusage is not supported on this environment" end times = 100.times.map { Process.times } - times.count { |t| ((t.utime * 1e6).to_i % 1000) > 0 }.should > 0 - times.count { |t| ((t.stime * 1e6).to_i % 1000) > 0 }.should > 0 + + # Creating custom matcher to show a debug message to investigate random failure + # on Debian ci.rvm.jp like: https://gist.github.com/ko1/346983a66ba66cf288249383ca30f15a + larger_than_0 = Class.new do + def initialize(expected, times:, gettimes:) + @expected = expected + @times = times + @gettimes = gettimes + end + + def matches?(actual) + @actual = actual + @actual > @expected + end + + def failure_message + ["Expected #{@actual} > #{@expected}", + "to be truthy but was false. (times: #{pp(@times)}, gettimes: #{pp(@gettimes)})"] + end + + alias :negative_failure_message :failure_message + + private def pp(obj) + require 'pp' + PP.pp(obj, '') + end + end.new(0, times: times, gettimes: gettimes) + + times.count { |t| ((t.utime * 1e6).to_i % 1000) > 0 }.should(larger_than_0) + times.count { |t| ((t.stime * 1e6).to_i % 1000) > 0 }.should(larger_than_0) end end end |