mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42579 from eileencodes/fix-nil-pool_config-in-legacy-handling
Fix nil pool_config in legacy connection handling
This commit is contained in:
commit
97b494fefb
2 changed files with 40 additions and 2 deletions
|
@ -23,8 +23,12 @@ module ActiveRecord
|
||||||
@name_to_pool_config[shard]
|
@name_to_pool_config[shard]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_pool_config(_, shard, pool_config)
|
def set_pool_config(role, shard, pool_config)
|
||||||
@name_to_pool_config[shard] = pool_config
|
if pool_config
|
||||||
|
@name_to_pool_config[shard] = pool_config
|
||||||
|
else
|
||||||
|
raise ArgumentError, "The `pool_config` for the :#{role} role and :#{shard} shard was `nil`. Please check your configuration. If you want your writing role to be something other than `:writing` set `config.active_record.writing_role` in your application configuration. The same setting should be applied for the `reading_role` if applicable."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,40 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
unless in_memory_db?
|
unless in_memory_db?
|
||||||
|
def test_not_setting_writing_role_while_using_another_named_role_raises
|
||||||
|
old_handler = ActiveRecord::Base.connection_handler
|
||||||
|
assert_deprecated do
|
||||||
|
ActiveRecord::Base.connection_handlers = { writing: ConnectionHandler.new }
|
||||||
|
end
|
||||||
|
ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handlers[:writing]
|
||||||
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
|
|
||||||
|
ActiveRecord::Base.connects_to(shards: { default: { all: :arunit }, one: { all: :arunit } })
|
||||||
|
|
||||||
|
assert_raises(ArgumentError) { setup_shared_connection_pool }
|
||||||
|
ensure
|
||||||
|
ActiveRecord::Base.connection_handler = old_handler
|
||||||
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_setting_writing_role_while_using_another_named_role_does_not_raise
|
||||||
|
old_role, ActiveRecord.writing_role = ActiveRecord.writing_role, :all
|
||||||
|
old_handler = ActiveRecord::Base.connection_handler
|
||||||
|
assert_deprecated do
|
||||||
|
ActiveRecord::Base.connection_handlers = { all: ConnectionHandler.new }
|
||||||
|
end
|
||||||
|
ActiveRecord::Base.connection_handler = ActiveRecord::Base.connection_handlers[:all]
|
||||||
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
|
|
||||||
|
ActiveRecord::Base.connects_to(shards: { default: { all: :arunit }, one: { all: :arunit } })
|
||||||
|
|
||||||
|
assert_nothing_raised { setup_shared_connection_pool }
|
||||||
|
ensure
|
||||||
|
ActiveRecord.writing_role = old_role
|
||||||
|
ActiveRecord::Base.connection_handler = old_handler
|
||||||
|
ActiveRecord::Base.establish_connection :arunit
|
||||||
|
end
|
||||||
|
|
||||||
def test_establish_connection_using_3_levels_config
|
def test_establish_connection_using_3_levels_config
|
||||||
previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env"
|
previous_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "default_env"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue