mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #40101 from tgxworld/fix_not_disconnecting_pool
Disconnect connections used for acquiring advisory lock in migration.
This commit is contained in:
commit
3d428777b0
2 changed files with 20 additions and 0 deletions
|
@ -1403,6 +1403,8 @@ module ActiveRecord
|
||||||
)
|
)
|
||||||
|
|
||||||
pool.with_connection { |connection| yield(connection) }
|
pool.with_connection { |connection| yield(connection) }
|
||||||
|
ensure
|
||||||
|
pool&.disconnect!
|
||||||
end
|
end
|
||||||
|
|
||||||
MIGRATOR_SALT = 2053462845
|
MIGRATOR_SALT = 2053462845
|
||||||
|
|
|
@ -933,6 +933,24 @@ class MigrationTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if current_adapter?(:PostgreSQLAdapter)
|
||||||
|
def test_with_advisory_lock_closes_connection
|
||||||
|
migration = Class.new(ActiveRecord::Migration::Current) {
|
||||||
|
def version; 100 end
|
||||||
|
def migrate(x)
|
||||||
|
end
|
||||||
|
}.new
|
||||||
|
|
||||||
|
migrator = ActiveRecord::Migrator.new(:up, [migration], @schema_migration, 100)
|
||||||
|
|
||||||
|
query = "SELECT COUNT(*) FROM pg_stat_activity WHERE datname = '#{ActiveRecord::Base.connection_db_config.database}'"
|
||||||
|
|
||||||
|
assert_no_changes -> { ActiveRecord::Base.connection.exec_query(query).rows.flatten.first } do
|
||||||
|
migrator.migrate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_with_advisory_lock_raises_the_right_error_when_it_fails_to_release_lock
|
def test_with_advisory_lock_raises_the_right_error_when_it_fails_to_release_lock
|
||||||
migration = Class.new(ActiveRecord::Migration::Current).new
|
migration = Class.new(ActiveRecord::Migration::Current).new
|
||||||
migrator = ActiveRecord::Migrator.new(:up, [migration], @schema_migration, 100)
|
migrator = ActiveRecord::Migrator.new(:up, [migration], @schema_migration, 100)
|
||||||
|
|
Loading…
Reference in a new issue