Commit 9541a0a 1 parent 4af852d commit 9541a0a Copy full SHA for 9541a0a
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 @@ -3896,7 +3896,7 @@ def up
3896
3896
)
3897
3897
end
3898
3898
3899
- it "releases the lock ( even after an exception) " do
3899
+ it "releases the lock even after an exception" do
3900
3900
begin
3901
3901
migration . safely_acquire_lock_for_table ( table_name ) do
3902
3902
raise "bogus error"
@@ -3907,6 +3907,32 @@ def up
3907
3907
expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
3908
3908
end
3909
3909
3910
+ it "releases the lock even after a swallowed postgres exception" do
3911
+ migration . safely_acquire_lock_for_table ( table_name ) do
3912
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to contain_exactly (
3913
+ having_attributes (
3914
+ table : "bogus_table" ,
3915
+ lock_type : "AccessExclusiveLock" ,
3916
+ granted : true ,
3917
+ pid : kind_of ( Integer ) ,
3918
+ ) ,
3919
+ )
3920
+
3921
+ begin
3922
+ migration . connection . execute ( "SELECT * FROM garbage" )
3923
+ rescue
3924
+ end
3925
+
3926
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
3927
+
3928
+ expect do
3929
+ migration . connection . execute ( "SELECT * FROM bogus_table" )
3930
+ end . to raise_error ( ActiveRecord ::StatementInvalid , /PG::InFailedSqlTransaction/ )
3931
+ end
3932
+
3933
+ expect ( locks_for_table ( table_name , connection : alternate_connection ) ) . to be_empty
3934
+ end
3935
+
3910
3936
it "waits to acquire a lock if the table is already blocked" do
3911
3937
block_call_count = 0
3912
3938
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