1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add test cases for Cache#fetch instrumentation

This commit is contained in:
Robin Clowers 2015-08-30 18:12:58 -07:00
parent 29886d9304
commit a948490b9c

View file

@ -490,6 +490,34 @@ module CacheStoreBehavior
assert_equal({key => "bar"}, @cache.read_multi(key)) assert_equal({key => "bar"}, @cache.read_multi(key))
assert @cache.delete(key) assert @cache.delete(key)
end end
def test_cache_hit_instrumentation
key = "test_key"
subscribe_executed = false
ActiveSupport::Notifications.subscribe "cache_read.active_support" do |name, start, finish, id, payload|
subscribe_executed = true
assert_equal :fetch, payload[:super_operation]
assert payload[:hit]
end
assert @cache.write(key, "1", :raw => true)
assert @cache.fetch(key) {}
assert subscribe_executed
ensure
ActiveSupport::Notifications.unsubscribe "cache_read.active_support"
end
def test_cache_miss_instrumentation
subscribe_executed = false
ActiveSupport::Notifications.subscribe "cache_read.active_support" do |name, start, finish, id, payload|
subscribe_executed = true
assert_equal :fetch, payload[:super_operation]
assert_not payload[:hit]
end
assert_not @cache.fetch("bad_key") {}
assert subscribe_executed
ensure
ActiveSupport::Notifications.unsubscribe "cache_read.active_support"
end
end end
# https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters # https://rails.lighthouseapp.com/projects/8994/tickets/6225-memcachestore-cant-deal-with-umlauts-and-special-characters