mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix flaky advisory lock test.
Random failures due to active connection checking within the assert_no_changes block. Failure: MigrationTest#test_with_advisory_lock_closes_connection [/rails/activerecord/test/cases/migration_test.rb:947]: --- expected +++ actual @@ -1 +1 @@ -["SELECT 1", "SELECT 1"] +["SELECT 1", "SELECT 1", "SELECT 1"] This commit scopes the query down further to ensure that the advisory unlock query is not left in pg_stat_activity which is an indication that the connection pool was not disconnected.
This commit is contained in:
parent
5699122abf
commit
d2215580d8
1 changed files with 9 additions and 1 deletions
|
@ -942,7 +942,15 @@ class MigrationTest < ActiveRecord::TestCase
|
||||||
}.new
|
}.new
|
||||||
|
|
||||||
migrator = ActiveRecord::Migrator.new(:up, [migration], @schema_migration, 100)
|
migrator = ActiveRecord::Migrator.new(:up, [migration], @schema_migration, 100)
|
||||||
query = "SELECT query FROM pg_stat_activity WHERE datname = '#{ActiveRecord::Base.connection_db_config.database}' AND state = 'idle'"
|
lock_id = migrator.send(:generate_migrator_advisory_lock_id)
|
||||||
|
|
||||||
|
query = <<~SQL
|
||||||
|
SELECT query
|
||||||
|
FROM pg_stat_activity
|
||||||
|
WHERE datname = '#{ActiveRecord::Base.connection_db_config.database}'
|
||||||
|
AND state = 'idle'
|
||||||
|
AND query LIKE '%#{lock_id}%'
|
||||||
|
SQL
|
||||||
|
|
||||||
assert_no_changes -> { ActiveRecord::Base.connection.exec_query(query).rows.flatten } do
|
assert_no_changes -> { ActiveRecord::Base.connection.exec_query(query).rows.flatten } do
|
||||||
migrator.migrate
|
migrator.migrate
|
||||||
|
|
Loading…
Reference in a new issue