Skip to content

Commit

Permalink
Merge pull request #103 from mikz/monotonic-time
Browse files Browse the repository at this point in the history
use monotonic time
  • Loading branch information
mattwynne committed Feb 17, 2016
2 parents 96430b4 + cce8a1d commit b2f2add
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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

0 comments on commit b2f2add

Please sign in to comment.