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 #103

Merged
merged 1 commit into from
Feb 17, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/cucumber/core/test/timer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,26 @@ def sec
private

def time_in_nanoseconds
t = Time.now
t.to_i * 10 ** 9 + t.nsec
MonotonicTime.time_in_nanoseconds
end

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
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/cucumber/core/test/timer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ module Core
module Test
describe Timer do
before do
time = double
allow( Time ).to receive(:now) { time }
allow( time ).to receive(:nsec).and_return(946752000, 946752001)
allow( time ).to receive(:to_i).and_return(1377009235, 1377009235)
allow(Timer::MonotonicTime).to receive(:time_in_nanoseconds)
.and_return(525702744080000, 525702744080001)
end

it "returns a Result::Duration object" do
Expand Down