aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-07-08 15:06:53 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-07-08 15:43:49 +0800
commit10ed7f580ebdfe53848424268455257c9eb729c6 (patch)
tree3416bb1465edb539737dd111bcf23da90dd76892 /activerecord/test/cases
parent7d699dad334996838dd529e4b75e1648692d56f8 (diff)
downloadrails-10ed7f580ebdfe53848424268455257c9eb729c6.tar.gz
rails-10ed7f580ebdfe53848424268455257c9eb729c6.tar.bz2
rails-10ed7f580ebdfe53848424268455257c9eb729c6.zip
Fix query cache when using shared connections
Enables the query cache on the correct connection when shared connections across threads are enabled
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/query_cache_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index 53a4963909..79bd6906d1 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -536,6 +536,23 @@ class QueryCacheTest < ActiveRecord::TestCase
ActiveRecord::Base.connection_handlers = { writing: ActiveRecord::Base.default_connection_handler }
end
+ test "query cache is enabled in threads with shared connection" do
+ ActiveRecord::Base.connection_pool.lock_thread = true
+
+ assert_cache :off
+
+ thread_a = Thread.new do
+ middleware { |env|
+ assert_cache :clean
+ [200, {}, nil]
+ }.call({})
+ end
+
+ thread_a.join
+
+ ActiveRecord::Base.connection_pool.lock_thread = false
+ end
+
private
def with_temporary_connection_pool
old_pool = ActiveRecord::Base.connection_handler.retrieve_connection_pool(ActiveRecord::Base.connection_specification_name)