diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-04-19 20:01:49 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-04-22 21:21:35 +0900 |
commit | c5529aa5fc9cad4334bcb8ba36b96a9ea09c54e6 (patch) | |
tree | 4260ba3237c89dcdcb535d954c6a5d910f999407 /spec/ruby/core/process | |
parent | 4cff7a92b8c97bb86dc1027b674a688f5182e302 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7739
Diffstat (limited to 'spec/ruby/core/process')
-rw-r--r-- | spec/ruby/core/process/times_spec.rb | 13 |
1 files 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 |