Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ruby 3.2, 3.3 and Rails 7.1 #3

Merged
merged 9 commits into from
May 26, 2024
16 changes: 11 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ jobs:
- '2.7'
- '3.0'
- '3.1'
- '3.2'
- '3.3'
activerecord-version:
- '6'
- '7'
- '6_0'
- '6_1'
- '7_0'
- '7_1'
exclude:
- # activerecord-7 doesn't support Ruby 2.6
ruby-version: '2.6'
activerecord-version: '7'
# activerecord-7 doesn't support Ruby 2.6
- ruby-version: '2.6'
activerecord-version: '7_0'
- ruby-version: '2.6'
activerecord-version: '7_1'

services:
mysql:
Expand Down
2 changes: 0 additions & 2 deletions gemfiles/activerecord_6.gemfile

This file was deleted.

2 changes: 2 additions & 0 deletions gemfiles/activerecord_6_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval_gemfile("../Gemfile")
gem "activerecord", "~> 6.0.0"
2 changes: 2 additions & 0 deletions gemfiles/activerecord_6_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval_gemfile("../Gemfile")
gem "activerecord", "~> 6.1.0"
2 changes: 0 additions & 2 deletions gemfiles/activerecord_7.gemfile

This file was deleted.

2 changes: 2 additions & 0 deletions gemfiles/activerecord_7_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval_gemfile("../Gemfile")
gem "activerecord", "~> 7.0.0"
2 changes: 2 additions & 0 deletions gemfiles/activerecord_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eval_gemfile("../Gemfile")
gem "activerecord", "~> 7.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def display_innodb_status_section(section_name)
end
end

ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.descendants.each do |adapter|
adapter.prepend(ActiveRecord::DebugErrors::DisplayMySQLInformation)
end

class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
prepend ActiveRecord::DebugErrors::DisplayMySQLInformation
def self.inherited(base)
super
base.prepend(ActiveRecord::DebugErrors::DisplayMySQLInformation)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
it "displays connection owners and other threads" do
Thread.new { sleep 10 } # another thread

mutex = Mutex.new
cv = ConditionVariable.new

expect {
ActiveRecord::Base.connection # Ensure to acquire a connection
Array.new(ActiveRecord::Base.connection_pool.size) do
Thread.new do
ActiveRecord::Base.connection_pool.checkout(0.1)
mutex.synchronize do
ActiveRecord::Base.connection_pool.checkout(0.1)
cv.wait(mutex, 1)
rescue
cv.broadcast
raise
end
end
end.each(&:join)
}.to raise_error(ActiveRecord::ConnectionTimeoutError)
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
}

user_for_replica = 'activerecord-debug_errors'
ActiveRecord::Base.legacy_connection_handling = false
# For compatibility. Rails deprecated since 6.1 and removed this option since 7.1.
# https://github.com/rails/rails/pull/44827/commits/ad52c0a19714a1b87a7d0c626a8b364cf95414cf
if ActiveRecord::Base.respond_to?(:legacy_connection_handling)
ActiveRecord::Base.legacy_connection_handling = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is simply broken in Rails 7.1.

end
ActiveRecord::Base.configurations = {
default_env: {
primary: base_db_config,
Expand Down