diff options
author | fatkodima <fatkodima123@gmail.com> | 2018-02-05 18:46:55 +0200 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2018-02-05 11:57:14 -0800 |
commit | 3b5d940fe5868af0f31989054e8fb7d2d9d11ec9 (patch) | |
tree | 16b8480ccf884607ccb4bb23d28bbd07a0aa0a7c /activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb | |
parent | 1dfc3a248ac03b96696927159e5e1a00c8e96ec2 (diff) | |
download | rails-3b5d940fe5868af0f31989054e8fb7d2d9d11ec9.tar.gz rails-3b5d940fe5868af0f31989054e8fb7d2d9d11ec9.tar.bz2 rails-3b5d940fe5868af0f31989054e8fb7d2d9d11ec9.zip |
Add missing instrumentation to RedisCacheStore#read_multi
Diffstat (limited to 'activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb')
-rw-r--r-- | activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb b/activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb new file mode 100644 index 0000000000..4e8ff60eb3 --- /dev/null +++ b/activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +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 + + def test_write_multi_instrumentation + writes = { "a" => "aa", "b" => "bb" } + + events = with_instrumentation "write_multi" do + @cache.write_multi(writes) + end + + assert_equal %w[ cache_write_multi.active_support ], events.map(&:name) + assert_nil events[0].payload[:super_operation] + assert_equal({ "a" => "aa", "b" => "bb" }, events[0].payload[:key]) + end + + def test_instrumentation_with_fetch_multi_as_super_operation + @cache.write("b", "bb") + + events = with_instrumentation "read_multi" do + @cache.fetch_multi("a", "b") { |key| key * 2 } + end + + assert_equal %w[ cache_read_multi.active_support ], events.map(&:name) + assert_equal :fetch_multi, events[0].payload[:super_operation] + 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" + + [].tap do |events| + ActiveSupport::Notifications.subscribe event_name do |*args| + events << ActiveSupport::Notifications::Event.new(*args) + end + yield + end + ensure + ActiveSupport::Notifications.unsubscribe event_name + end +end |