Skip to content

Commit

Permalink
Support nil ActiveRecord logger (#39)
Browse files Browse the repository at this point in the history
* Support nil logger

* Fix silence for older rails version

* Fixes PR reviews

* Simplify with_polling_volume method

* Fixes PR reviews

* Fixes PR reviews
  • Loading branch information
navidemad authored Sep 28, 2024
1 parent a4d0c56 commit bd349b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/action_cable/subscription_adapter/solid_cable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def broadcast_messages
end

def with_polling_volume
if ::SolidCable.silence_polling?
if ::SolidCable.silence_polling? && ActiveRecord::Base.logger
ActiveRecord::Base.logger.silence { yield }
else
yield
Expand Down
Binary file added test/dummy/solid_cable_test-shm
Binary file not shown.
Empty file added test/dummy/solid_cable_test-wal
Empty file.
20 changes: 20 additions & 0 deletions test/lib/action_cable/subscription_adapter/solid_cable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ class ActionCable::SubscriptionAdapter::SolidCableTest < ActionCable::TestCase
end
end

test "does not raise error when polling with no Active Record logger" do
with_active_record_logger(nil) do
assert_nothing_raised do
subscribe_as_queue("channel") do |queue|
@tx_adapter.broadcast("channel", "hello world")

assert_equal "hello world", queue.pop
end
end
end
end

private
def cable_config
{ adapter: "solid_cable", message_retention: "1.second",
Expand All @@ -159,4 +171,12 @@ def subscribe_as_queue(channel, adapter = @rx_adapter)
ensure
adapter.unsubscribe(channel, callback) if subscribed.set?
end

def with_active_record_logger(logger)
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = logger
yield
ensure
ActiveRecord::Base.logger = old_logger
end
end

0 comments on commit bd349b3

Please sign in to comment.