Sha256: 4fbc6278c46935e10472f80f84509bd43a399499dc75baffc06ddf9f6ec0119d

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

require "helper"

class CacheInstrumentationTest < ActiveSupport::TestCase
  attr_reader :cache

  setup :setup_subscriber, :setup_cache
  teardown :teardown_subscriber, :teardown_cache

  def setup_subscriber
    @subscriber = Nunes::Subscribers::ActiveSupport.subscribe(adapter)
  end

  def teardown_subscriber
    ActiveSupport::Notifications.unsubscribe @subscriber if @subscriber
  end

  def setup_cache
    ActiveSupport::Cache::MemoryStore.instrument = true
    @cache = ActiveSupport::Cache::MemoryStore.new
  end

  def teardown_cache
    ActiveSupport::Cache::MemoryStore.instrument = nil
    @cache = nil
  end

  test "cache_read miss" do
    cache.read('foo')

    assert_timer "active_support.cache.read"
    assert_counter "active_support.cache.miss"
  end

  test "cache_read hit" do
    cache.write('foo', 'bar')
    adapter.clear
    cache.read('foo')

    assert_timer "active_support.cache.read"
    assert_counter "active_support.cache.hit"
  end

  test "cache_generate" do
    cache.fetch('foo') { |key| :generate_me_please }
    assert_timer "active_support.cache.fetch_generate"
  end

  test "cache_fetch with hit" do
    cache.write('foo', 'bar')
    adapter.clear
    cache.fetch('foo') { |key| :never_gets_here }

    assert_timer "active_support.cache.fetch"
    assert_timer "active_support.cache.fetch_hit"
  end

  test "cache_fetch with miss" do
    cache.fetch('foo') { 'foo value set here' }

    assert_timer "active_support.cache.fetch"
    assert_timer "active_support.cache.fetch_generate"
    assert_timer "active_support.cache.write"
  end

  test "cache_write" do
    cache.write('foo', 'bar')
    assert_timer "active_support.cache.write"
  end

  test "cache_delete" do
    cache.delete('foo')
    assert_timer "active_support.cache.delete"
  end

  test "cache_exist?" do
    cache.exist?('foo')
    assert_timer "active_support.cache.exist"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nunes-0.3.1 test/cache_instrumentation_test.rb
nunes-0.3.0 test/cache_instrumentation_test.rb
nunes-0.2.0 test/cache_instrumentation_test.rb