Skip to content

Commit 83fa6f8

Browse files
tgwizardbyroot
authored andcommitted
Include options when instrumenting ActiveSupport::Cache::Store delete
1 parent cc2800a commit 83fa6f8

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Include options when instrumenting `ActiveSupport::Cache::Store#delete` and `ActiveSupport::Cache::Store#delete_multi`.
2+
3+
*Adam Renberg Tamm*
4+
15
* Print test names when running `rails test -v` for parallel tests.
26

37
*John Hawthorn*, *Abeid Ahmed*

activesupport/lib/active_support/cache.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def delete(name, options = nil)
677677
options = merged_options(options)
678678
key = normalize_key(name, options)
679679

680-
instrument(:delete, key) do
680+
instrument(:delete, key, options) do
681681
delete_entry(key, **options)
682682
end
683683
end
@@ -692,7 +692,7 @@ def delete_multi(names, options = nil)
692692
options = merged_options(options)
693693
names.map! { |key| normalize_key(key, options) }
694694

695-
instrument_multi :delete_multi, names do
695+
instrument_multi(:delete_multi, names, options) do
696696
delete_multi_entries(names, **options)
697697
end
698698
end

activesupport/test/cache/behaviors/cache_instrumentation_behavior.rb

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,60 @@ def test_read_multi_instrumentation
6464
assert_equal @cache.class.name, events[0].payload[:store]
6565
end
6666

67+
def test_read_instrumentation
68+
key = SecureRandom.uuid
69+
@cache.write(key, SecureRandom.alphanumeric)
70+
71+
events = with_instrumentation "read" do
72+
@cache.read(key)
73+
end
74+
75+
assert_equal %w[ cache_read.active_support ], events.map(&:name)
76+
assert_equal normalized_key(key), events[0].payload[:key]
77+
assert_same true, events[0].payload[:hit]
78+
assert_equal @cache.class.name, events[0].payload[:store]
79+
end
80+
81+
def test_write_instrumentation
82+
key = SecureRandom.uuid
83+
84+
events = with_instrumentation "write" do
85+
@cache.write(key, SecureRandom.alphanumeric)
86+
end
87+
88+
assert_equal %w[ cache_write.active_support ], events.map(&:name)
89+
assert_equal normalized_key(key), events[0].payload[:key]
90+
assert_equal @cache.class.name, events[0].payload[:store]
91+
end
92+
93+
def test_delete_instrumentation
94+
key = SecureRandom.uuid
95+
96+
options = { namespace: "foo" }
97+
events = with_instrumentation "delete" do
98+
@cache.delete(key, options)
99+
end
100+
101+
assert_equal %w[ cache_delete.active_support ], events.map(&:name)
102+
assert_equal normalized_key(key, options), events[0].payload[:key]
103+
assert_equal @cache.class.name, events[0].payload[:store]
104+
assert_equal "foo", events[0].payload[:namespace]
105+
end
106+
107+
def test_delete_multi_instrumentation
108+
key_1 = SecureRandom.uuid
109+
key_2 = SecureRandom.uuid
110+
111+
options = { namespace: "foo" }
112+
events = with_instrumentation "delete_multi" do
113+
@cache.delete_multi([key_2, key_1], options)
114+
end
115+
116+
assert_equal %w[ cache_delete_multi.active_support ], events.map(&:name)
117+
assert_equal [normalized_key(key_2, options), normalized_key(key_1, options)], events[0].payload[:key]
118+
assert_equal @cache.class.name, events[0].payload[:store]
119+
end
120+
67121
def test_increment_instrumentation
68122
key_1 = SecureRandom.uuid
69123
@cache.write(key_1, 0)
@@ -103,7 +157,7 @@ def with_instrumentation(method)
103157
ActiveSupport::Notifications.unsubscribe event_name
104158
end
105159

106-
def normalized_key(key)
107-
@cache.send(:normalize_key, key, @cache.options)
160+
def normalized_key(key, options = nil)
161+
@cache.send(:normalize_key, key, options)
108162
end
109163
end

0 commit comments

Comments
 (0)