summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-23 11:54:31 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-23 12:01:13 +0900
commitdafbaabc04e5a2d34045af78629a7249fd8c7481 (patch)
treea5a8002acda4709796fc93870f1f0c6047581766 /spec
parentc5529aa5fc9cad4334bcb8ba36b96a9ea09c54e6 (diff)
downloadruby-dafbaabc04e5a2d34045af78629a7249fd8c7481.tar.gz
Check the precision of `getrusage` at runtime
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/process/times_spec.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 1cf8d5e8bb..d2610f6415 100644
--- a/spec/ruby/core/process/times_spec.rb
+++ b/spec/ruby/core/process/times_spec.rb
@@ -17,8 +17,18 @@ describe "Process.times" do
end
end
+ # TODO: The precision of `getrusage` depends on platforms (OpenBSD
+ # seems not supporting under-milliseconds in fact); this example is
+ # very questionable as an example of Ruby, and it just repeats the
+ # guard condition.
guard -> do
- Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
+ 1000.times.any? do
+ # If getrusage has precision beyond milliseconds, there will be
+ # very likely at least one non-zero microsecond results when
+ # repeating enough.
+ time = Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID)
+ not ('%.6f' % time).end_with?('000')
+ end
rescue Errno::EINVAL
false
end do