Sha256: aec029183f97dc57a179b909c3c8c538520cf92017a4c570b3269fcde0188201

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'helper'
require 'toy/instrumentation/statsd'

describe Toy::Instrumentation::StatsdSubscriber do
  uses_constants('User')

  let(:statsd_client) { Statsd.new }
  let(:socket) { FakeUDPSocket.new }

  before do
    described_class.client = statsd_client
    Thread.current[:statsd_socket] = socket
    Toy.instrumenter = ActiveSupport::Notifications
  end

  after do
    described_class.client = nil
    Thread.current[:statsd_socket] = nil
  end

  def assert_timer(metric)
    regex = /#{Regexp.escape metric}\:\d+\|ms/
    socket.buffer.detect { |op| op.first =~ regex }.should_not be_nil
  end

  it "updates timers when calls happen" do
    user = User.create(:name => 'Joe')
    assert_timer('toystore.create')
    assert_timer('toystore.User.create')

    user.update_attributes(:name => 'John')
    assert_timer('toystore.update')
    assert_timer('toystore.User.update')

    user.destroy
    assert_timer('toystore.destroy')
    assert_timer('toystore.User.destroy')

    User.read(user.id)
    assert_timer('toystore.read')
    assert_timer('toystore.User.read')

    User.read_multiple([user.id])
    assert_timer('toystore.read_multiple')
    assert_timer('toystore.User.read_multiple')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toystore-0.13.2 spec/toy/instrumentation/statsd_subscriber_spec.rb