From 5806c54447439f2ba22892e4045e78dd80f96f0c Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 28 Mar 2020 14:39:01 +0100 Subject: Improve reliability of the Process.times spec --- spec/ruby/core/process/times_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'spec') 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 -- cgit v1.2.3