diff --git a/lib/statsd.rb b/lib/statsd.rb index dfddf1d..e3bfff5 100644 --- a/lib/statsd.rb +++ b/lib/statsd.rb @@ -89,7 +89,7 @@ def timing(stat, ms, sample_rate=1); send stat, ms, 'ms', sample_rate end def time(stat, sample_rate=1) start = Time.now result = yield - timing(stat, ((Time.now - start) * 1000).round, sample_rate) + timing(stat, ((Time.now - start) * 1000).round(5), sample_rate) result end diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index 6c6523c..ab6c582 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -71,7 +71,11 @@ def socket; @socket ||= FakeUDPSocket.new end describe "#time" do it "should format the message according to the statsd spec" do @statsd.time('foobar') { sleep(0.001); 'test' } - @statsd.socket.recv.must_equal ['foobar:1|ms'] + data = @statsd.socket.recv + key, value, unit = data.first.split(/[:|]/) + key.must_equal "foobar" + value.must_match /^\d\.\d{3}$/ + unit.must_equal "ms" end it "should return the result of the block" do @@ -84,7 +88,12 @@ def socket; @socket ||= FakeUDPSocket.new end it "should format the message according to the statsd spec" do result = @statsd.time('foobar', 0.5) { sleep(0.001); 'test' } - @statsd.socket.recv.must_equal ['foobar:1|ms|@0.5'] + data = @statsd.socket.recv + key, value, unit, frequency = data.first.split(/[:|]/) + key.must_equal "foobar" + value.must_match /^\d\.\d{3}$/ + unit.must_equal "ms" + frequency.must_equal "@0.5" end end end diff --git a/statsd-ruby.gemspec b/statsd-ruby.gemspec index 8853f5f..120261b 100644 --- a/statsd-ruby.gemspec +++ b/statsd-ruby.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{statsd-ruby} - s.version = "0.3.0.github.2" + s.version = "0.3.0.github.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Rein Henrichs"]