Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only setup shared pools if we have a connection #45773

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions activerecord/lib/active_record/test_fixtures.rb
Expand Up @@ -117,7 +117,6 @@ def setup_fixtures(config = ActiveRecord::Base)
@connection_subscriber = ActiveSupport::Notifications.subscribe("!connection.active_record") do |_, _, _, _, payload|
connection_name = payload[:connection_name] if payload.key?(:connection_name)
shard = payload[:shard] if payload.key?(:shard)
setup_shared_connection_pool

if connection_name
begin
Expand All @@ -126,10 +125,14 @@ def setup_fixtures(config = ActiveRecord::Base)
connection = nil
end

if connection && !@fixture_connections.include?(connection)
connection.begin_transaction joinable: false, _lazy: false
connection.pool.lock_thread = true if lock_threads
@fixture_connections << connection
if connection
setup_shared_connection_pool

if !@fixture_connections.include?(connection)
connection.begin_transaction joinable: false, _lazy: false
connection.pool.lock_thread = true if lock_threads
@fixture_connections << connection
end
end
end
end
Expand Down
Expand Up @@ -6,8 +6,6 @@
module ActiveRecord
module ConnectionAdapters
class ConnectionHandlerTest < ActiveRecord::TestCase
self.use_transactional_tests = false

fixtures :people

def setup
Expand Down Expand Up @@ -74,6 +72,23 @@ def test_not_setting_writing_role_while_using_another_named_role_raises
ActiveRecord::Base.establish_connection :arunit
end

def test_fixtures_dont_raise_if_theres_no_writing_pool_config
connection_handler = ActiveRecord::Base.connection_handler
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new

assert_nothing_raised do
ActiveRecord::Base.connects_to(database: { reading: :arunit, writing: :arunit })
end

rw_conn = ActiveRecord::Base.connection_handler.retrieve_connection("ActiveRecord::Base", role: :writing)
ro_conn = ActiveRecord::Base.connection_handler.retrieve_connection("ActiveRecord::Base", role: :reading)

assert_equal rw_conn, ro_conn
ensure
ActiveRecord::Base.connection_handler = connection_handler
ActiveRecord::Base.establish_connection :arunit
end

def test_setting_writing_role_while_using_another_named_role_does_not_raise
connection_handler = ActiveRecord::Base.connection_handler
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
Expand Down