Skip to content

Commit

Permalink
use monotonic time
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed May 10, 2016
1 parent d500493 commit cb0d704
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
26 changes: 26 additions & 0 deletions lib/ci/reporter/monotonic_time.rb
@@ -0,0 +1,26 @@
module CI
module Reporter
module MonotonicTime
module_function

if defined?(Process::CLOCK_MONOTONIC)
def time_in_nanoseconds
Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
end
elsif (defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby') == 'jruby'
def time_in_nanoseconds
java.lang.System.nanoTime()
end
else
def time_in_nanoseconds
t = Time.now
t.to_i * 10 ** 9 + t.nsec
end
end

def time_in_seconds
time_in_nanoseconds / 10 ** 9.0
end
end
end
end
12 changes: 7 additions & 5 deletions lib/ci/reporter/test_suite.rb
@@ -1,6 +1,7 @@
require 'time'
require 'builder'
require 'ci/reporter/output_capture'
require 'ci/reporter/monotonic_time'

module CI
module Reporter
Expand Down Expand Up @@ -38,7 +39,8 @@ def initialize(name)

# Starts timing the test suite.
def start
@start = Time.now
@start_time = Time.now
@start = MonotonicTime.time_in_seconds
unless ENV['CI_CAPTURE'] == "off"
@capture_out = OutputCapture.wrap($stdout) {|io| $stdout = io }
@capture_err = OutputCapture.wrap($stderr) {|io| $stderr = io }
Expand All @@ -48,8 +50,8 @@ def start
# Finishes timing the test suite.
def finish
self.tests = testcases.size
self.time = Time.now - @start
self.timestamp = @start.iso8601
self.time = MonotonicTime.time_in_seconds - @start
self.timestamp = @start_time.iso8601
self.failures = testcases.map(&:failure_count).reduce(&:+)
self.errors = testcases.map(&:error_count).reduce(&:+)
self.skipped = testcases.count(&:skipped?)
Expand Down Expand Up @@ -93,12 +95,12 @@ def initialize(*args)

# Starts timing the test.
def start
@start = Time.now
@start = MonotonicTime.time_in_seconds
end

# Finishes timing the test.
def finish
self.time = Time.now - @start
self.time = MonotonicTime.time_in_seconds - @start
end

# Returns non-nil if the test failed.
Expand Down

0 comments on commit cb0d704

Please sign in to comment.