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

ruby-changes:59041

From: Takashi <ko1@a...>
Date: Mon, 2 Dec 2019 17:19:44 +0900 (JST)
Subject: [ruby-changes:59041] a47d6c256f (master): Fix random failure on getusage-missing environments

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

From a47d6c256ff684392f00516a917735a14aec64b0 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Mon, 2 Dec 2019 00:12:29 -0800
Subject: Fix random failure on getusage-missing environments

`* 1e6` makes a spurious result about floating point number's precision.

```
irb(main)[01:0]> 16.028
=> 16.028
irb(main)[02:0]> (16.028 * 1e6)
=> 16027999.999999998
```

diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 510ea89..16f1bb7 100644
--- a/spec/ruby/core/process/times_spec.rb
+++ b/spec/ruby/core/process/times_spec.rb
@@ -16,42 +16,14 @@ 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
-        gettimes = 100.times.map { Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) }
-        if gettimes.count { |t| ((t * 1e6).to_i % 1000) > 0 } == 0
+        times = 100.times.map { Process.clock_gettime(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID) }
+        if times.count { |t| !('%.6f' % t).end_with?('000') } == 0
           skip "getrusage is not supported on this environment"
         end
 
         times = 100.times.map { Process.times }
-
-        # Creating custom matcher to show a debug message to investigate random failure
-        # on Debian ci.rvm.jp like: https://gist.github.com/ko1/346983a66ba66cf288249383ca30f15a
-        larger_than_0 = Class.new do
-          def initialize(expected, times:, gettimes:)
-            @expected = expected
-            @times = times
-            @gettimes = gettimes
-          end
-
-          def matches?(actual)
-            @actual = actual
-            @actual > @expected
-          end
-
-          def failure_message
-            ["Expected #{@actual} > #{@expected}",
-             "to be truthy but was false. (times: #{pp(@times)}, gettimes: #{pp(@gettimes)})"]
-          end
-
-          alias :negative_failure_message :failure_message
-
-          private def pp(obj)
-            require 'pp'
-            PP.pp(obj, '')
-          end
-        end.new(0, times: times, gettimes: gettimes)
-
-        times.count { |t| ((t.utime * 1e6).to_i % 1000) > 0 }.should(larger_than_0)
-        times.count { |t| ((t.stime * 1e6).to_i % 1000) > 0 }.should(larger_than_0)
+        times.count { |t| !('%.6f' % t.utime).end_with?('000') }.should > 0
+        times.count { |t| !('%.6f' % t.stime).end_with?('000') }.should > 0
       end
     end
   end
-- 
cgit v0.10.2


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

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