2015-07-12 11:07:31 -04:00
|
|
|
require 'ostruct'
|
|
|
|
|
|
|
|
class TestServer
|
2015-07-12 12:44:46 -04:00
|
|
|
include ActionCable::Server::Connections
|
2016-03-11 18:32:02 -05:00
|
|
|
include ActionCable::Server::Broadcasting
|
2015-07-12 12:44:46 -04:00
|
|
|
|
2016-03-11 18:32:02 -05:00
|
|
|
attr_reader :logger, :config, :mutex
|
2015-07-12 11:07:31 -04:00
|
|
|
|
2016-03-11 18:32:02 -05:00
|
|
|
def initialize(subscription_adapter: SuccessAdapter)
|
2015-07-12 11:07:31 -04:00
|
|
|
@logger = ActiveSupport::TaggedLogging.new ActiveSupport::Logger.new(StringIO.new)
|
2016-03-11 18:32:02 -05:00
|
|
|
|
|
|
|
@config = OpenStruct.new(log_tags: [], subscription_adapter: subscription_adapter)
|
2016-03-01 19:50:19 -05:00
|
|
|
@config.use_faye = ENV['FAYE'].present?
|
|
|
|
@config.client_socket_class = if @config.use_faye
|
|
|
|
ActionCable::Connection::FayeClientSocket
|
|
|
|
else
|
|
|
|
ActionCable::Connection::ClientSocket
|
|
|
|
end
|
2016-03-11 18:32:02 -05:00
|
|
|
|
|
|
|
@mutex = Monitor.new
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|
|
|
|
|
2016-01-16 10:33:50 -05:00
|
|
|
def pubsub
|
2016-03-11 18:32:02 -05:00
|
|
|
@pubsub ||= @config.subscription_adapter.new(self)
|
2015-07-12 11:07:31 -04:00
|
|
|
end
|
2015-10-15 22:11:49 -04:00
|
|
|
|
2016-03-01 19:50:19 -05:00
|
|
|
def event_loop
|
|
|
|
@event_loop ||= if @config.use_faye
|
|
|
|
ActionCable::Connection::FayeEventLoop.new
|
|
|
|
else
|
|
|
|
ActionCable::Connection::StreamEventLoop.new
|
|
|
|
end
|
2015-10-15 22:11:49 -04:00
|
|
|
end
|
2016-02-24 23:01:19 -05:00
|
|
|
|
|
|
|
def worker_pool
|
|
|
|
@worker_pool ||= ActionCable::Server::Worker.new(max_size: 5)
|
|
|
|
end
|
2015-07-12 11:07:31 -04:00
|
|
|
end
|