Skip to content

Commit

Permalink
Address `ActiveRecord::InstrumentationTest#test_payload_connection_wi…
Browse files Browse the repository at this point in the history
…th_query_cache_enabled` failure

This commit addresses `ActiveRecord::InstrumentationTest#test_payload_connection_with_query_cache_enabled` failure
with `postgresql` adapter because it executes `SHOW search_path` adds another notification that is executed via `sql_key`.
This statements is not executed by other database adapters.

- Failures fixed by this commit

```ruby
$ ARCONN=postgresql bin/test test/cases/instrumentation_test.rb -n test_payload_connection_with_query_cache_enabled
Using postgresql
Run options: -n test_payload_connection_with_query_cache_enabled --seed 65179

F

Failure:
ActiveRecord::InstrumentationTest#test_payload_connection_with_query_cache_enabled [test/cases/instrumentation_test.rb:142]:
Expected 2 instead of 3 notifications for sql.active_record.
Expected: 2
  Actual: 3

bin/test test/cases/instrumentation_test.rb:138

Finished in 0.029114s, 34.3482 runs/s, 34.3482 assertions/s.
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
$
```

Fix rails#53858
Related to rails#53822
  • Loading branch information
yahonda committed Dec 6, 2024
1 parent cd8ecdb commit 2566083
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions activerecord/test/cases/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ def test_payload_connection_with_query_cache_disabled
def test_payload_connection_with_query_cache_enabled
connection = ClothingItem.lease_connection

payloads = capture_notifications("sql.active_record") do
assert_notifications_count("sql.active_record", 2) do
Book.cache do
Book.first
Book.first
end
notifications = capture_notifications("sql.active_record") do
Book.cache do
Book.first
Book.first
end
end.map(&:payload)
end

payloads = notifications.select { _1.payload[:sql].match?("SELECT") }.map(&:payload)

assert_equal 2, payloads.size
assert_equal connection, payloads.first[:connection]
assert_equal connection, payloads.second[:connection]
end
Expand Down

0 comments on commit 2566083

Please sign in to comment.