mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add missing instrumentation to RedisCacheStore#read_multi
This commit is contained in:
parent
1dfc3a248a
commit
3b5d940fe5
7 changed files with 25 additions and 18 deletions
|
@ -187,7 +187,11 @@ module ActiveSupport
|
|||
# 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
|
||||
|
|
1
activesupport/test/cache/behaviors.rb
vendored
1
activesupport/test/cache/behaviors.rb
vendored
|
@ -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"
|
||||
|
|
|
@ -1,28 +1,15 @@
|
|||
# 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 @@ class FileStoreTest < ActiveSupport::TestCase
|
|||
include LocalCacheBehavior
|
||||
include CacheDeleteMatchedBehavior
|
||||
include CacheIncrementDecrementBehavior
|
||||
include CacheInstrumentationBehavior
|
||||
include AutoloadingCacheBehavior
|
||||
|
||||
def test_clear
|
||||
|
|
|
@ -49,6 +49,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase
|
|||
include CacheStoreVersionBehavior
|
||||
include LocalCacheBehavior
|
||||
include CacheIncrementDecrementBehavior
|
||||
include CacheInstrumentationBehavior
|
||||
include EncodedKeyCacheBehavior
|
||||
include AutoloadingCacheBehavior
|
||||
include ConnectionPoolBehavior
|
||||
|
|
|
@ -14,6 +14,7 @@ class MemoryStoreTest < ActiveSupport::TestCase
|
|||
include CacheStoreVersionBehavior
|
||||
include CacheDeleteMatchedBehavior
|
||||
include CacheIncrementDecrementBehavior
|
||||
include CacheInstrumentationBehavior
|
||||
|
||||
def test_prune_size
|
||||
@cache.write(1, "aaaaaaaaaa") && sleep(0.001)
|
||||
|
|
|
@ -107,6 +107,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
|||
include CacheStoreVersionBehavior
|
||||
include LocalCacheBehavior
|
||||
include CacheIncrementDecrementBehavior
|
||||
include CacheInstrumentationBehavior
|
||||
include AutoloadingCacheBehavior
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue