Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/statsd.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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

Expand Down
13 changes: 11 additions & 2 deletions spec/statsd_spec.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand All@@ -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
Expand Down
2 changes: 1 addition & 1 deletion statsd-ruby.gemspec
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Expand Down