diff options
author | Guo Xiang Tan <tgx_world@hotmail.com> | 2017-11-21 13:20:15 +0800 |
---|---|---|
committer | Guo Xiang Tan <tgx_world@hotmail.com> | 2017-11-21 13:21:41 +0800 |
commit | 0bd7f4ad44c53832ec029a53a88461e9f6eab6f1 (patch) | |
tree | 2cae31fb8881fa651a388495cdacd89e365c64cb /activerecord/test | |
parent | 3e304e8177bc1fd81d9d8db15eaf252cf386e22f (diff) | |
download | rails-0bd7f4ad44c53832ec029a53a88461e9f6eab6f1.tar.gz rails-0bd7f4ad44c53832ec029a53a88461e9f6eab6f1.tar.bz2 rails-0bd7f4ad44c53832ec029a53a88461e9f6eab6f1.zip |
Raise an error if advisory lock in migrator was not released.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index b18af2ab55..85107c26d3 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -678,6 +678,25 @@ class MigrationTest < ActiveRecord::TestCase assert_no_column Person, :last_name, "without an advisory lock, the Migrator should not make any changes, but it did." end + + def test_with_advisory_lock_raises_the_right_error_when_it_fails_to_release_lock + migration = Class.new(ActiveRecord::Migration::Current).new + migrator = ActiveRecord::Migrator.new(:up, [migration], 100) + lock_id = migrator.send(:generate_migrator_advisory_lock_id) + + e = assert_raises(ActiveRecord::ConcurrentMigrationError) do + silence_stream($stderr) do + migrator.send(:with_advisory_lock) do + ActiveRecord::Base.connection.release_advisory_lock(lock_id) + end + end + end + + assert_match( + /#{ActiveRecord::ConcurrentMigrationError::RELEASE_LOCK_FAILED_MESSAGE}/, + e.message + ) + end end private |