Skip to content

Commit 07b512c

Browse files
committed
Fix test: follow ActiveRecord 8.1 behavior
In ActiveRecord 8.1+, replica connections cannot execute lock queries, so it raises ActiveRecord::ReadOnlyError instead of ActiveRecord::Deadlocked.
1 parent dd79e4e commit 07b512c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

spec/activerecord/debug_errors/ext/connection_adapters/abstract_mysql_adapter_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ def cause_deadlock(role:)
5858

5959
context "when the user doesn't have the permission to execute 'SHOW ENGINE INNODB STATUS'" do
6060
it "displays an error message" do
61+
# In ActiveRecord 8.1+, replica connections cannot execute lock queries,
62+
# so it raises ActiveRecord::ReadOnlyError instead of ActiveRecord::Deadlocked.
63+
expected_error = ActiveRecord.version < Gem::Version.new("8.1") ? ActiveRecord::Deadlocked : ActiveRecord::ReadOnlyError
64+
6165
expect {
6266
ActiveRecord::Base.connected_to(role: :reading) do
6367
cause_deadlock(role: :reading)
6468
end
65-
}.to raise_error(ActiveRecord::Deadlocked)
69+
}.to raise_error(expected_error)
6670
expect(log.string).to include("Failed to execute")
6771
end
6872
end

0 commit comments

Comments
 (0)