summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-03-28 14:39:01 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-03-28 14:39:01 +0100
commit5806c54447439f2ba22892e4045e78dd80f96f0c (patch)
treed57950d7bc3c3e323c10afcbfca52dc9e6647aa4
parent6413a26b6c90aeb6768cc1fa1dcf69de8e6bf36f (diff)
Improve reliability of the Process.times spec
-rw-r--r--spec/ruby/core/process/times_spec.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 8ab91da8ce..2ec9924d16 100644
--- a/spec/ruby/core/process/times_spec.rb
+++ b/spec/ruby/core/process/times_spec.rb
@@ -16,13 +16,21 @@ 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 = 1000.times.map { Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) }
- if times.count { |t| !('%.6f' % t).end_with?('000') } == 0
+ max = 10_000
+ has_getrusage = max.times.find do
+ time = Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
+ ('%.6f' % time).end_with?('000')
+ end
+ unless has_getrusage
skip "getrusage is not supported on this environment"
end
- times = 1000.times.map { Process.times }
- times.count { |t| !('%.6f' % t.utime).end_with?('000') }.should > 0
+ found = (max * 10).times.find do
+ time = Process.times.utime
+ ('%.6f' % time).end_with?('000')
+ end
+
+ found.should_not == nil
end
end
end