Skip to content

Commit 55bc09d

Browse files
committed
Add process extenstion to use Procss.clock_gettime with timecop
Signed-off-by: Yuta Iwama <[email protected]>
1 parent 578c07d commit 55bc09d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test/helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def to_masked_element
5050
require 'fluent/time'
5151
require 'serverengine'
5252
require 'helpers/fuzzy_assert'
53+
require 'helpers/process_extenstion'
5354

5455
module Fluent
5556
module Plugin

test/helpers/process_extenstion.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'timecop'
2+
3+
module Process
4+
class << self
5+
# this can be used with timecop
6+
def clock_gettime(clock_id, unit = :float_second)
7+
if Process::CLOCK_REALTIME
8+
t = Time.now
9+
10+
case unit
11+
when :float_second
12+
t.to_i + t.nsec / 1_000_000_000.0
13+
when :float_millisecond
14+
t.to_i * 1_000 + t.nsec / 1_000_000.0
15+
when :float_microsecond
16+
t.to_i * 1_000_000 + t.nsec / 1_000.0
17+
when :second
18+
t.to_i
19+
when :millisecond
20+
t.to_i * 1000 + t.nsec / 1_000_000
21+
when :microsecond
22+
t.to_i * 1_000_000 + t.nsec / 1_000
23+
when :nanosecond
24+
t.to_i * 1_000_000_000 + t.nsec
25+
end
26+
else
27+
# TODO
28+
super
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)