instance method setup_shared_connection_pool

Ruby on Rails 6.0.6

Since v6.0.6 Private

Available in: v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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

Type at least 2 characters to search.

↑↓ navigate · open · esc close