-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 7 commits
08b8284
e508ef6
5f9a8c9
1688bd0
6214941
ca6d8e4
9cc944f
d2a4654
6dbd03f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eval_gemfile("../Gemfile") | ||
gem "activerecord", "~> 6.0.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eval_gemfile("../Gemfile") | ||
gem "activerecord", "~> 6.1.0" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eval_gemfile("../Gemfile") | ||
gem "activerecord", "~> 7.0.0" |
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 |
---|---|---|
|
@@ -18,13 +18,16 @@ | |
|
||
describe "#acquire_connection" do | ||
it "displays connection owners and other threads" do | ||
ActiveRecord::Base.connection_pool.checkout_timeout = 0.001 # no need to delay test suite by waiting the whole full default timeout | ||
|
||
Thread.new { sleep 10 } # another thread | ||
|
||
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) | ||
ActiveRecord::Base.connection_pool.checkout | ||
sleep 0.001 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Connection pool handling in Rails 7.1 is so smarter that the existing test cannot cause ref: 1688bd0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid that this test becomes flaky because some threads might end before the last thread calls diff --git a/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb b/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb
index 7a86bc7..6f2b1fe 100644
--- a/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb
+++ b/spec/activerecord/debug_errors/ext/connection_adapters/connection_pool_spec.rb
@@ -20,11 +20,20 @@ RSpec.describe ActiveRecord::DebugErrors::DisplayConnectionOwners do
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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. And to be honest, I couldn't think of any other way to do it, so I'm glad to know the cool way you suggested it. Updated d2a4654 |
||
end | ||
end.each(&:join) | ||
}.to raise_error(ActiveRecord::ConnectionTimeoutError) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented in 5f9a8c9, there is a case when neither
raw_execute
norexecute
is called in Rails 7.1.I'm not sure if this way is the best, I tried to use
translate_exception_class
as a hook for Rails 7.1.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the following approach is similar to the original one and more readable. What do you think about them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code you presented is quite neat!
I think, I'm probably misunderstanding something big (and my implementation has based on the misunderstanding), but could you please explain to me why your code still works in Rails 7.1 for further studies? (and why the original code doesn't work.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see below,
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#raw_execute
is not implemented, whereas the subclasses have the methodraw_execute
, so appending the module to the subclasses works expectedly:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I got it now. Thanks for your explanation!