2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
2015-07-14 11:58:46 -04:00
|
|
|
|
|
|
|
class WorkerTest < ActiveSupport::TestCase
|
|
|
|
class Receiver
|
|
|
|
attr_accessor :last_action
|
|
|
|
|
|
|
|
def run
|
|
|
|
@last_action = :run
|
|
|
|
end
|
|
|
|
|
|
|
|
def process(message)
|
|
|
|
@last_action = [ :process, message ]
|
|
|
|
end
|
2015-10-15 22:11:49 -04:00
|
|
|
|
|
|
|
def connection
|
2016-01-24 05:43:40 -05:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def logger
|
2016-02-06 14:40:42 -05:00
|
|
|
# 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: [])
|
2015-10-15 22:11:49 -04:00
|
|
|
end
|
2015-07-14 11:58:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@worker = ActionCable::Server::Worker.new
|
|
|
|
@receiver = Receiver.new
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
@receiver.last_action = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invoke" do
|
2016-04-15 02:04:42 -04:00
|
|
|
@worker.invoke @receiver, :run, connection: @receiver.connection
|
2015-07-14 11:58:46 -04:00
|
|
|
assert_equal :run, @receiver.last_action
|
|
|
|
end
|
|
|
|
|
|
|
|
test "invoke with arguments" do
|
2016-04-15 02:04:42 -04:00
|
|
|
@worker.invoke @receiver, :process, "Hello", connection: @receiver.connection
|
2015-07-14 11:58:46 -04:00
|
|
|
assert_equal [ :process, "Hello" ], @receiver.last_action
|
|
|
|
end
|
|
|
|
end
|