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 replace existing pools in transactional tests #40487

Merged
merged 1 commit into from
Oct 29, 2020
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
1 change: 1 addition & 0 deletions activerecord/lib/active_record/test_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def setup_shared_connection_pool
pool_manager.shard_names.each do |shard_name|
writing_pool_config = pool_manager.get_pool_config(ActiveRecord::Base.writing_role, shard_name)
pool_manager.role_names.each do |role|
next unless pool_manager.get_pool_config(role, shard_name)
pool_manager.set_pool_config(role, shard_name, writing_pool_config)
end
end
Expand Down
30 changes: 30 additions & 0 deletions activerecord/test/cases/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,21 @@ def test_writing_and_reading_connections_are_the_same
assert_equal rw_conn, ro_conn
end

def test_only_existing_connections_are_replaced
ActiveRecord::Base.connects_to shards: {
default: { writing: :default, reading: :readonly },
two: { writing: :default }
}

setup_shared_connection_pool

assert_raises(ActiveRecord::ConnectionNotEstablished) do
ActiveRecord::Base.connected_to(role: :reading, shard: :two) do
ActiveRecord::Base.retrieve_connection
end
end
end

private
def config
{ "default" => default_config, "readonly" => readonly_config }
Expand Down Expand Up @@ -1516,6 +1531,21 @@ def test_writing_and_reading_connections_are_the_same_with_legacy_handling
assert_equal rw_conn, ro_conn
end

def test_only_existing_connections_are_replaced
ActiveRecord::Base.connects_to shards: {
default: { writing: :default, reading: :readonly },
two: { writing: :default }
}

setup_shared_connection_pool

assert_raises(ActiveRecord::ConnectionNotEstablished) do
ActiveRecord::Base.connected_to(role: :reading, shard: :two) do
ActiveRecord::Base.retrieve_connection
end
end
end

private
def config
{ "default" => default_config, "readonly" => readonly_config }
Expand Down