From 76fb33dbe1053a867a6cffd8347b486d9af1f40f Mon Sep 17 00:00:00 2001 From: Jean byroot Boussier Date: Mon, 19 Feb 2024 12:22:21 +0100 Subject: [PATCH] Fix: Trilogy ActiveRecord adapter to be compatible with latest Rails edge. (#520) The `connection` method was removed in https://github.com/rails/rails/commit/6f3b46b02d190b18747a27772b0511dab71c8315 Co-authored-by: Jean Boussier --- .rubocop.yml | 3 +++ CHANGELOG.md | 2 ++ lib/semian/activerecord_trilogy_adapter.rb | 8 ++++---- test/adapters/activerecord_trilogy_adapter_test.rb | 8 ++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7f7af8b5..3734fd6b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -54,3 +54,6 @@ Style/SingleLineMethods: Style/SpecialGlobalVars: Enabled: false + +Minitest/AssertInDelta: + Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index be10a3ad..6f7923bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/semian/activerecord_trilogy_adapter.rb b/lib/semian/activerecord_trilogy_adapter.rb index 48a25bf1..554ea7d5 100644 --- a/lib/semian/activerecord_trilogy_adapter.rb +++ b/lib/semian/activerecord_trilogy_adapter.rb @@ -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 diff --git a/test/adapters/activerecord_trilogy_adapter_test.rb b/test/adapters/activerecord_trilogy_adapter_test.rb index 6fdceda7..1fbbb438 100644 --- a/test/adapters/activerecord_trilogy_adapter_test.rb +++ b/test/adapters/activerecord_trilogy_adapter_test.rb @@ -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)