Permalink
Browse files

Don't rely on the global server as a receiver.

The `WorkerTest`'s `Receiver` is imporsonating an `ActionCable::Connection::Base`, but
just delegates the logger to `ActionCable.logger`.

This creates a mismatch as the connection requires the logger to be a
`TaggedLoggerProxy`'ied logger, while the server doesn't.

Thus to ensure an exception isn't raised when the worker tries to call `tag`
other tests have to assign a proxied logger to their test server.

Instead of forcing change on other tests, have Receiver adhere to the connection
contract and use a `TaggedLoggerProxy`.

As a consequence remove more setup from the tests.
  • Loading branch information...
kaspth committed Feb 6, 2016
1 parent 861ece9 commit 3ae8eb13cb4967f533339ecddf93e19f06caa6d2
@@ -12,11 +12,9 @@ class ClientTest < ActionCable::TestCase
WAIT_WHEN_NOT_EXPECTING_EVENT = 0.2
def setup
# TODO: ActionCable requires a *lot* of setup at the moment...
ActionCable.instance_variable_set(:@server, nil)
server = ActionCable.server
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.logger = ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
server.config.logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.cable = { adapter: 'async' }.with_indifferent_access
@@ -9,13 +9,7 @@ module CommonSubscriptionAdapterTest
WAIT_WHEN_NOT_EXPECTING_EVENT = 0.2
def setup
# TODO: ActionCable requires a *lot* of setup at the moment...
server = ActionCable::Server::Base.new
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.logger = ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
# and now the "real" setup for our test:
server.config.cable = cable_config.with_indifferent_access
adapter_klass = server.config.pubsub_adapter
@@ -17,7 +17,9 @@ def connection
end
def logger
ActionCable.server.logger
# Impersonating a connection requires a TaggedLoggerProxy'ied logger.
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
end
end

0 comments on commit 3ae8eb1

Please sign in to comment.