Skip to content

Commit

Permalink
Fix: Trilogy ActiveRecord adapter to be compatible with latest Rails …
Browse files Browse the repository at this point in the history
…edge. (#520)

The `connection` method was removed in rails/rails@6f3b46b

Co-authored-by: Jean Boussier <[email protected]>
  • Loading branch information
casperisfine and byroot authored Feb 19, 2024
1 parent e52d99d commit 76fb33d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
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

0 comments on commit 76fb33d

Please sign in to comment.