未验证 提交 c327f4dc 编写于 作者: F fatkodima 提交者: Jeremy Daer

Add missing instrumentation to RedisCacheStore#read_multi

上级 87238c3e
......@@ -187,7 +187,11 @@ def inspect
# fetched values.
def read_multi(*names)
if mget_capable?
read_multi_mget(*names)
instrument(:read_multi, names, options) do |payload|
read_multi_mget(*names).tap do |results|
payload[:hits] = results.keys
end
end
else
super
end
......
......@@ -3,6 +3,7 @@
require_relative "behaviors/autoloading_cache_behavior"
require_relative "behaviors/cache_delete_matched_behavior"
require_relative "behaviors/cache_increment_decrement_behavior"
require_relative "behaviors/cache_instrumentation_behavior"
require_relative "behaviors/cache_store_behavior"
require_relative "behaviors/cache_store_version_behavior"
require_relative "behaviors/connection_pool_behavior"
......
# frozen_string_literal: true
require "abstract_unit"
require "active_support/cache"
class CacheStoreWriteMultiEntriesStoreProviderInterfaceTest < ActiveSupport::TestCase
setup do
@cache = ActiveSupport::Cache.lookup_store(:null_store)
end
test "fetch_multi uses write_multi_entries store provider interface" do
module CacheInstrumentationBehavior
def test_fetch_multi_uses_write_multi_entries_store_provider_interface
assert_called_with(@cache, :write_multi_entries) do
@cache.fetch_multi "a", "b", "c" do |key|
key * 2
end
end
end
end
class CacheStoreWriteMultiInstrumentationTest < ActiveSupport::TestCase
setup do
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
end
test "instrumentation" do
def test_write_multi_instrumentation
writes = { "a" => "aa", "b" => "bb" }
events = with_instrumentation "write_multi" do
......@@ -34,7 +21,7 @@ class CacheStoreWriteMultiInstrumentationTest < ActiveSupport::TestCase
assert_equal({ "a" => "aa", "b" => "bb" }, events[0].payload[:key])
end
test "instrumentation with fetch_multi as super operation" do
def test_instrumentation_with_fetch_multi_as_super_operation
@cache.write("b", "bb")
events = with_instrumentation "read_multi" do
......@@ -46,6 +33,17 @@ class CacheStoreWriteMultiInstrumentationTest < ActiveSupport::TestCase
assert_equal ["b"], events[0].payload[:hits]
end
def test_read_multi_instrumentation
@cache.write("b", "bb")
events = with_instrumentation "read_multi" do
@cache.read_multi("a", "b") { |key| key * 2 }
end
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal ["b"], events[0].payload[:hits]
end
private
def with_instrumentation(method)
event_name = "cache_#{method}.active_support"
......
......@@ -30,6 +30,7 @@ def cache_dir
include LocalCacheBehavior
include CacheDeleteMatchedBehavior
include CacheIncrementDecrementBehavior
include CacheInstrumentationBehavior
include AutoloadingCacheBehavior
def test_clear
......
......@@ -49,6 +49,7 @@ def setup
include CacheStoreVersionBehavior
include LocalCacheBehavior
include CacheIncrementDecrementBehavior
include CacheInstrumentationBehavior
include EncodedKeyCacheBehavior
include AutoloadingCacheBehavior
include ConnectionPoolBehavior
......
......@@ -14,6 +14,7 @@ def setup
include CacheStoreVersionBehavior
include CacheDeleteMatchedBehavior
include CacheIncrementDecrementBehavior
include CacheInstrumentationBehavior
def test_prune_size
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
......
......@@ -107,6 +107,7 @@ class RedisCacheStoreCommonBehaviorTest < StoreTest
include CacheStoreVersionBehavior
include LocalCacheBehavior
include CacheIncrementDecrementBehavior
include CacheInstrumentationBehavior
include AutoloadingCacheBehavior
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册