[前][次][番号順一覧][スレッド一覧]

ruby-changes:60554

From: Benoit <ko1@a...>
Date: Sat, 28 Mar 2020 22:43:18 +0900 (JST)
Subject: [ruby-changes:60554] 5806c54447 (master): Improve reliability of the Process.times spec

https://git.ruby-lang.org/ruby.git/commit/?id=5806c54447

From 5806c54447439f2ba22892e4045e78dd80f96f0c Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Sat, 28 Mar 2020 14:39:01 +0100
Subject: Improve reliability of the Process.times spec


diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 8ab91da..2ec9924 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/times_spec.rb#L16
   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 v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]