aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-02-21 09:41:36 +1030
committerGitHub <noreply@github.com>2017-02-21 09:41:36 +1030
commit0ce641839aa59d8c8306ec21cfd5f31aaa9b169c (patch)
tree7da92c4b25a0f7afe124b5a0e6c136d8f13d5504 /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
parentab0146075ab063f601030178f3e1da56e886199e (diff)
parentd6466beb9fff9f2ba4f73673e65f087dd6bba488 (diff)
downloadrails-0ce641839aa59d8c8306ec21cfd5f31aaa9b169c.tar.gz
rails-0ce641839aa59d8c8306ec21cfd5f31aaa9b169c.tar.bz2
rails-0ce641839aa59d8c8306ec21cfd5f31aaa9b169c.zip
Merge pull request #28083 from eileencodes/ensure-test-threads-shared-db-conn
Ensure test threads share a DB connection
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index ce4721c99d..3f2e86a98d 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -353,6 +353,16 @@ module ActiveRecord
@threads_blocking_new_connections = 0
@available = ConnectionLeasingQueue.new self
+
+ @lock_thread = false
+ end
+
+ def lock_thread=(lock_thread)
+ if lock_thread
+ @lock_thread = Thread.current
+ else
+ @lock_thread = nil
+ end
end
# Retrieve the connection associated with the current thread, or call
@@ -361,7 +371,7 @@ module ActiveRecord
# #connection can be called any number of times; the connection is
# held in a cache keyed by a thread.
def connection
- @thread_cached_conns[connection_cache_key(Thread.current)] ||= checkout
+ @thread_cached_conns[connection_cache_key(@lock_thread || Thread.current)] ||= checkout
end
# Returns true if there is an open connection being used for the current thread.