Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix: Trilogy ActiveRecord adapter to be compatible with latest Rails edge. #520

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ Style/SingleLineMethods:

Style/SpecialGlobalVars:
Enabled: false

Minitest/AssertInDelta:
Enabled: false
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Fix: Trilogy ActiveRecord adapter to be compatible with latest Rails edge.

# v0.21.2
* Change: Trilogy ActiveRecord adapter will not bypass "SAVEPOINT RELEASE" unless it uses the ActiveRecord default name and only 2 levels of nesting
* Change: The bypass for COMMIT/ROLLBACK statements assumes current ActiveRecord behaviour, that is no blank spaces or ";" chracter at the end of the statement
Expand Down
8 changes: 4 additions & 4 deletions lib/semian/activerecord_trilogy_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ def active?
end

def with_resource_timeout(temp_timeout)
if connection.nil?
if @raw_connection.nil?
prev_read_timeout = @config[:read_timeout] || 0
@config.merge!(read_timeout: temp_timeout) # Create new client with temp_timeout for read timeout
else
prev_read_timeout = connection.read_timeout
connection.read_timeout = temp_timeout
prev_read_timeout = @raw_connection.read_timeout
@raw_connection.read_timeout = temp_timeout
end
yield
ensure
@config.merge!(read_timeout: prev_read_timeout)
connection&.read_timeout = prev_read_timeout
@raw_connection&.read_timeout = prev_read_timeout
end

private
Expand Down
8 changes: 8 additions & 0 deletions test/adapters/activerecord_trilogy_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ def test_circuit_open_errors_do_not_trigger_the_circuit_breaker
end
end

def test_with_resource_timeout
assert_equal(2.0, @adapter.raw_connection.read_timeout)
@adapter.with_resource_timeout(0.5) do
assert_equal(0.5, @adapter.raw_connection.read_timeout)
end
assert_equal(2.0, @adapter.raw_connection.read_timeout)
end

private

def trilogy_adapter(**config_overrides)
Expand Down
Loading