-
Notifications
You must be signed in to change notification settings - Fork 151
Remove excess memoization of ConnAdapter instances #318
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29b3e8a
Don't memoize connection borrowed from activerecord pool
kolen 6782abe
Don't memoize default_conn_adapter in Queue state
kolen b45f66d
Fix "undefined variable" warning for 'ruby -w'
kolen 49e8da1
Add test for integration with real ActiveRecord
kolen 9ee03eb
Remove old unused method [skip ci]
kolen 514fda5
Add changelog entry
kolen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'helper' | ||
| require 'active_record' | ||
|
|
||
| class QueueClassicActiverecordIntegrationTest < QCTest | ||
| def setup | ||
| super | ||
| reset_globals | ||
| ActiveRecord::Base.establish_connection "#{ENV["DATABASE_URL"]}?pool=1" | ||
| end | ||
|
|
||
| def teardown | ||
| super | ||
| end | ||
|
|
||
| def test_connection_not_returned_to_pool | ||
| take_connection_until_checked = Mutex.new | ||
| conn_adapter_ready = Queue.new | ||
| connection_from_adapter = nil | ||
| take_connection_until_checked.synchronize do | ||
| Thread.new do | ||
| with_env 'QC_RAILS_DATABASE' => 'true' do | ||
| conn_adapter_ready.push QC.default_conn_adapter.connection | ||
| end | ||
| take_connection_until_checked.synchronize {} | ||
| ActiveRecord::Base.clear_active_connections! | ||
| end | ||
|
|
||
| connection_from_adapter = conn_adapter_ready.pop | ||
|
|
||
| ActiveRecord::Base.connection_pool.reap | ||
|
|
||
| # Pool now has no free connections available | ||
| assert_raises(ActiveRecord::ConnectionTimeoutError) do | ||
| ActiveRecord::Base.connection_pool.checkout 0.1 | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 it makes sense to move this part to the top (as an early
return), because ifrails_connection_sharing_enabled?istrue, thent = Thread.currentetc lines are effectively dead.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.
There's another
returnbefore this, in order for setter to work. If thread-local:qc_conn_adapteris set before with setter, it's returned regardless ofrails_connection_sharing_enabled?.This setter is a little odd (even in master), as it sets default_conn_adapter only for current thread. After this changes, this behavior is retained. I think such setters are better to be deprecated.
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 see. For a future reviewer, if we forget about setter, the proposed change in essence is: