Skip to content

Commit

Permalink
Add process extenstion to use Procss.clock_gettime with timecop
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Aug 14, 2019
1 parent 578c07d commit 55bc09d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def to_masked_element
require 'fluent/time'
require 'serverengine'
require 'helpers/fuzzy_assert'
require 'helpers/process_extenstion'

module Fluent
module Plugin
Expand Down
32 changes: 32 additions & 0 deletions test/helpers/process_extenstion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'timecop'

module Process
class << self
# this can be used with timecop
def clock_gettime(clock_id, unit = :float_second)
if Process::CLOCK_REALTIME
t = Time.now

case unit
when :float_second
t.to_i + t.nsec / 1_000_000_000.0
when :float_millisecond
t.to_i * 1_000 + t.nsec / 1_000_000.0
when :float_microsecond
t.to_i * 1_000_000 + t.nsec / 1_000.0
when :second
t.to_i
when :millisecond
t.to_i * 1000 + t.nsec / 1_000_000
when :microsecond
t.to_i * 1_000_000 + t.nsec / 1_000
when :nanosecond
t.to_i * 1_000_000_000 + t.nsec
end
else
# TODO
super
end
end
end
end

0 comments on commit 55bc09d

Please sign in to comment.