From c5529aa5fc9cad4334bcb8ba36b96a9ea09c54e6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 19 Apr 2023 20:01:49 +0900 Subject: [PATCH] Fix a guard of `Process.times` `GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID` clock uses `getrusage` always if available as the name states. That is if it is implemented `getrusage` is available, regardless microseconds in its results. --- spec/ruby/core/process/times_spec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb index 30504ca3cf..1cf8d5e8bb 100644 --- a/spec/ruby/core/process/times_spec.rb +++ b/spec/ruby/core/process/times_spec.rb @@ -17,16 +17,13 @@ describe "Process.times" do end end - platform_is_not :windows do + guard -> do + Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) + rescue Errno::EINVAL + false + end do it "uses getrusage when available to improve precision beyond milliseconds" do 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 found = (max * 100).times.find do time = Process.times.utime