Commit 2cfa43d 1 parent 97605a0 commit 2cfa43d Copy full SHA for 2cfa43d
File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -4131,7 +4131,7 @@ def up
4131
4131
)
4132
4132
end
4133
4133
4134
- it "releases the lock ( even after an exception) " do
4134
+ it "releases the lock even after an exception" do
4135
4135
begin
4136
4136
migration . safely_acquire_lock_for_table ( table_name ) do
4137
4137
raise "bogus error"
@@ -4142,6 +4142,32 @@ def up
4142
4142
expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
4143
4143
end
4144
4144
4145
+ it "releases the lock even after a swallowed postgres exception" do
4146
+ migration . safely_acquire_lock_for_table ( table_name ) do
4147
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to contain_exactly (
4148
+ having_attributes (
4149
+ table : "bogus_table" ,
4150
+ lock_type : "AccessExclusiveLock" ,
4151
+ granted : true ,
4152
+ pid : kind_of ( Integer ) ,
4153
+ ) ,
4154
+ )
4155
+
4156
+ begin
4157
+ migration . connection . execute ( "SELECT * FROM garbage" )
4158
+ rescue
4159
+ end
4160
+
4161
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
4162
+
4163
+ expect do
4164
+ migration . connection . execute ( "SELECT * FROM bogus_table" )
4165
+ end . to raise_error ( ActiveRecord ::StatementInvalid , /PG::InFailedSqlTransaction/ )
4166
+ end
4167
+
4168
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
4169
+ end
4170
+
4145
4171
it "waits to acquire a lock if the table is already blocked" do
4146
4172
block_call_count = 0
4147
4173
expect ( PgHaMigrations ::BlockingDatabaseTransactions ) . to receive ( :find_blocking_transactions ) . exactly ( 3 ) . times do |*args |
You can’t perform that action at this time.
0 commit comments