instance method
setup_shared_connection_pool
Ruby on Rails 6.0.6
Since v6.0.6 PrivateSignature
setup_shared_connection_pool()
Shares the writing connection pool with connections on other handlers.
In an application with a primary and replica the test fixtures need to share a connection pool so that the reading connection can see data in the open transaction on the writing connection.
Source
# File activerecord/lib/active_record/test_fixtures.rb, line 192
def setup_shared_connection_pool
writing_handler = ActiveRecord::Base.connection_handlers[ActiveRecord::Base.writing_role]
ActiveRecord::Base.connection_handlers.values.each do |handler|
if handler != writing_handler
handler.connection_pool_list.each do |pool|
name = pool.spec.name
writing_connection = writing_handler.retrieve_connection_pool(name)
return unless writing_connection
reading_connection = handler.send(:owner_to_pool)[name]
next if reading_connection == writing_connection
@saved_pool_configs[handler][name] = reading_connection
handler.send(:owner_to_pool)[name] = writing_connection
end
end
end
end
Defined in activerecord/lib/active_record/test_fixtures.rb line 192
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::TestFixtures