Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 4be5ca3

Browse files
committed
Merge pull request #10 from github/allow-floating-point-times
Allow floating point timings
2 parents 043e83d + 66937ef commit 4be5ca3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/statsd.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end
8989
def time(stat, sample_rate=1)
9090
start = Time.now
9191
result = yield
92-
timing(stat, ((Time.now - start) * 1000).round, sample_rate)
92+
timing(stat, ((Time.now - start) * 1000).round(5), sample_rate)
9393
result
9494
end
9595

spec/statsd_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ def socket; @socket ||= FakeUDPSocket.new end
7171
describe "#time" do
7272
it "should format the message according to the statsd spec" do
7373
@statsd.time('foobar') { sleep(0.001); 'test' }
74-
@statsd.socket.recv.must_equal ['foobar:1|ms']
74+
data = @statsd.socket.recv
75+
key, value, unit = data.first.split(/[:|]/)
76+
key.must_equal "foobar"
77+
value.must_match /^\d\.\d{3}$/
78+
unit.must_equal "ms"
7579
end
7680

7781
it "should return the result of the block" do
@@ -84,7 +88,12 @@ def socket; @socket ||= FakeUDPSocket.new end
8488

8589
it "should format the message according to the statsd spec" do
8690
result = @statsd.time('foobar', 0.5) { sleep(0.001); 'test' }
87-
@statsd.socket.recv.must_equal ['foobar:1|ms|@0.5']
91+
data = @statsd.socket.recv
92+
key, value, unit, frequency = data.first.split(/[:|]/)
93+
key.must_equal "foobar"
94+
value.must_match /^\d\.\d{3}$/
95+
unit.must_equal "ms"
96+
frequency.must_equal "@0.5"
8897
end
8998
end
9099
end

statsd-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Gem::Specification.new do |s|
77
s.name = %q{statsd-ruby}
8-
s.version = "0.3.0.github.2"
8+
s.version = "0.3.0.github.3"
99

1010
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
1111
s.authors = ["Rein Henrichs"]

0 commit comments

Comments
 (0)