2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "ostruct"
|
2015-07-12 11:07:31 -04:00
|
|
|
|
|
|
|
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-08-06 13:55:02 -04: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
|
2016-09-30 21:27:26 -04:00
|
|
|
@event_loop ||= ActionCable::Connection::StreamEventLoop.new.tap do |loop|
|
|
|
|
loop.instance_variable_set(:@executor, Concurrent.global_io_executor)
|
2016-08-08 12:17:28 -04:00
|
|
|
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
|