Skip to content
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

Include connection in cached query notifications #37328

Merged
merged 1 commit into from Oct 1, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -134,6 +134,7 @@ def cache_notification_info(sql, name, binds)
type_casted_binds: -> { type_casted_binds(binds) },
name: name,
connection_id: object_id,
connection: self,
cached: true
}
end
Expand Down
25 changes: 25 additions & 0 deletions activerecord/test/cases/instrumentation_test.rb
Expand Up @@ -72,5 +72,30 @@ def test_payload_name_on_destroy
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end

def test_payload_connection_with_query_cache_disabled
connection = Book.connection
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
assert_equal connection, event.payload[:connection]
end
Book.first
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end

def test_payload_connection_with_query_cache_enabled
connection = Book.connection
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
assert_equal connection, event.payload[:connection]
end
Book.cache do
Book.first
Book.first
end
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
end
end