Skip to content

Commit edf63be

Browse files
authored
Merge pull request rails#53494 from zzak/re-53492
Make sure query_cache config tests are using the right connection
2 parents 0e3e0d1 + aa388ff commit edf63be

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

activerecord/test/cases/query_cache_test.rb

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ def test_cache_is_not_applied_when_config_is_false
147147
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: false))
148148
end
149149

150-
mw = middleware { |env|
151-
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
152-
assert_not_predicate pool.lease_connection, :query_cache_enabled
153-
assert_nil pool.query_cache.instance_variable_get(:@max_size)
150+
mw = middleware do |env|
151+
ActiveRecord::Base.connected_to(role: :reading) do
152+
assert_cache :off
153+
assert_nil ActiveRecord::Base.lease_connection.pool.query_cache.instance_variable_get(:@max_size)
154154
end
155-
}
155+
end
156156

157157
mw.call({})
158158
ensure
@@ -165,12 +165,12 @@ def test_cache_is_applied_when_config_is_string
165165
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: "unlimited"))
166166
end
167167

168-
mw = middleware { |env|
169-
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
170-
assert_predicate pool.lease_connection, :query_cache_enabled
171-
assert_nil pool.query_cache.instance_variable_get(:@max_size)
168+
mw = middleware do |env|
169+
ActiveRecord::Base.connected_to(role: :reading) do
170+
assert_cache :clean
171+
assert_nil ActiveRecord::Base.lease_connection.pool.query_cache.instance_variable_get(:@max_size)
172172
end
173-
}
173+
end
174174

175175
mw.call({})
176176
ensure
@@ -183,12 +183,12 @@ def test_cache_is_applied_when_config_is_integer
183183
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: 42))
184184
end
185185

186-
mw = middleware { |env|
187-
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
188-
assert_predicate pool.lease_connection, :query_cache_enabled
189-
assert_equal 42, pool.query_cache.instance_variable_get(:@max_size)
186+
mw = middleware do |env|
187+
ActiveRecord::Base.connected_to(role: :reading) do
188+
assert_cache :clean
189+
assert_equal 42, ActiveRecord::Base.lease_connection.pool.query_cache.instance_variable_get(:@max_size)
190190
end
191-
}
191+
end
192192

193193
mw.call({})
194194
ensure
@@ -201,19 +201,18 @@ def test_cache_is_applied_when_config_is_nil
201201
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: nil))
202202
end
203203

204-
mw = middleware { |env|
205-
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
206-
assert_predicate pool.lease_connection, :query_cache_enabled
204+
mw = middleware do |env|
205+
ActiveRecord::Base.connected_to(role: :reading) do
206+
assert_cache :clean
207+
assert_equal ActiveRecord::ConnectionAdapters::QueryCache::DEFAULT_SIZE, ActiveRecord::Base.lease_connection.pool.query_cache.instance_variable_get(:@max_size)
207208
end
208-
}
209+
end
209210

210211
mw.call({})
211212
ensure
212213
clean_up_connection_handler
213214
end
214215

215-
216-
217216
if Process.respond_to?(:fork) && !in_memory_db?
218217
def test_query_cache_with_forked_processes
219218
ActiveRecord::Base.connected_to(role: :reading) do

0 commit comments

Comments
 (0)