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

Add tests for empty fetch

This commit is contained in:
John Hawthorn 2020-01-17 15:34:14 -08:00
parent cdfcf555af
commit 5b5c37eaf7

View file

@ -30,20 +30,43 @@ module CacheInstrumentationBehavior
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal :fetch_multi, events[0].payload[:super_operation]
assert_equal ["a", "b"], events[0].payload[:key]
assert_equal ["b"], events[0].payload[:hits]
end
def test_instrumentation_empty_fetch_multi
events = with_instrumentation "read_multi" do
@cache.fetch_multi() { |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 [], events[0].payload[:key]
assert_equal [], 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 }
@cache.read_multi("a", "b")
end
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal ["a", "b"], events[0].payload[:key]
assert_equal ["b"], events[0].payload[:hits]
end
def test_empty_read_multi_instrumentation
events = with_instrumentation "read_multi" do
@cache.read_multi()
end
assert_equal %w[ cache_read_multi.active_support ], events.map(&:name)
assert_equal [], events[0].payload[:key]
assert_equal [], events[0].payload[:hits]
end
private
def with_instrumentation(method)
event_name = "cache_#{method}.active_support"