diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2019-01-04 08:49:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-04 08:49:17 -0500 |
commit | 725c6422e763cd676b1dc70e4d3d392b4fd5b43f (patch) | |
tree | 880f5013d7d5b2d297611703714013718d49c04c /activerecord/lib | |
parent | a5a22c4ea142974117d6afbde68a8074617bda0c (diff) | |
parent | b24bfcce771645bd45ea249327bac8b8e08c2e6c (diff) | |
download | rails-725c6422e763cd676b1dc70e4d3d392b4fd5b43f.tar.gz rails-725c6422e763cd676b1dc70e4d3d392b4fd5b43f.tar.bz2 rails-725c6422e763cd676b1dc70e4d3d392b4fd5b43f.zip |
Merge pull request #34773 from eileencodes/share-fixture-connections-with-multiple-handlers
For fixtures share the connection pool when there are multiple handlers
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/test_fixtures.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/test_fixtures.rb b/activerecord/lib/active_record/test_fixtures.rb index 7b7b3f7112..d29fc9f84b 100644 --- a/activerecord/lib/active_record/test_fixtures.rb +++ b/activerecord/lib/active_record/test_fixtures.rb @@ -173,10 +173,33 @@ module ActiveRecord end def enlist_fixture_connections + setup_shared_connection_pool + ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection) end private + + # 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. + def setup_shared_connection_pool + writing_handler = ActiveRecord::Base.connection_handler + + 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) + handler.send(:owner_to_pool)[name] = writing_connection + end + end + end + end + def load_fixtures(config) fixtures = ActiveRecord::FixtureSet.create_fixtures(fixture_path, fixture_table_names, fixture_class_names, config) Hash[fixtures.map { |f| [f.name, f] }] |