Skip to content

Commit 72fd341

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 72fd341

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ 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-
expect {
62-
ActiveRecord::Base.connected_to(role: :reading) do
63-
cause_deadlock(role: :reading)
64-
end
65-
}.to raise_error(ActiveRecord::Deadlocked)
66-
expect(log.string).to include("Failed to execute")
61+
# In ActiveRecord 8.1+, replica connections cannot execute lock queries,
62+
# so it raises ActiveRecord::ReadOnlyError instead of ActiveRecord::Deadlocked.
63+
if ActiveRecord.version >= Gem::Version.new("8.1")
64+
expect {
65+
ActiveRecord::Base.connected_to(role: :reading) do
66+
cause_deadlock(role: :reading)
67+
end
68+
}.to raise_error(ActiveRecord::ReadOnlyError)
69+
else
70+
expect {
71+
ActiveRecord::Base.connected_to(role: :reading) do
72+
cause_deadlock(role: :reading)
73+
end
74+
}.to raise_error(ActiveRecord::Deadlocked)
75+
expect(log.string).to include("Failed to execute")
76+
end
6777
end
6878
end
6979
end

0 commit comments

Comments
 (0)