Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use monotonic time #160

Merged
merged 1 commit into from Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/ci/reporter/monotonic_time.rb
@@ -0,0 +1,22 @@
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
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