2017-07-16 17:10:15 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 17:15:15 +00:00
|
|
|
require "action_cable"
|
|
|
|
require "active_support/testing/autorun"
|
2019-08-02 04:24:21 +00:00
|
|
|
require "active_support/testing/method_call_assertions"
|
2015-01-15 17:28:02 +00:00
|
|
|
|
2016-08-06 17:15:15 +00:00
|
|
|
require "puma"
|
|
|
|
require "rack/mock"
|
2016-03-11 23:32:02 +00:00
|
|
|
|
2015-07-13 15:43:52 +00:00
|
|
|
# Require all the stubs and models
|
2017-05-15 14:17:28 +00:00
|
|
|
Dir[File.expand_path("stubs/*.rb", __dir__)].each { |file| require file }
|
2015-07-14 15:58:46 +00:00
|
|
|
|
2018-08-19 23:23:33 +00:00
|
|
|
# Set test adapter and logger
|
|
|
|
ActionCable.server.config.cable = { "adapter" => "test" }
|
2018-08-23 09:36:19 +00:00
|
|
|
ActionCable.server.config.logger = Logger.new(nil)
|
2018-08-19 23:23:33 +00:00
|
|
|
|
2016-10-01 01:27:26 +00:00
|
|
|
class ActionCable::TestCase < ActiveSupport::TestCase
|
2019-08-02 04:24:21 +00:00
|
|
|
include ActiveSupport::Testing::MethodCallAssertions
|
|
|
|
|
2016-01-28 04:55:31 +00:00
|
|
|
def wait_for_async
|
2016-04-15 06:04:42 +00:00
|
|
|
wait_for_executor Concurrent.global_io_executor
|
2015-10-16 02:11:49 +00:00
|
|
|
end
|
2016-01-24 10:43:40 +00:00
|
|
|
|
2016-01-28 04:55:31 +00:00
|
|
|
def run_in_eventmachine
|
|
|
|
yield
|
|
|
|
wait_for_async
|
2016-01-24 10:43:40 +00:00
|
|
|
end
|
2016-04-15 06:04:42 +00:00
|
|
|
|
|
|
|
def wait_for_executor(executor)
|
2016-09-19 09:29:23 +00:00
|
|
|
# do not wait forever, wait 2s
|
|
|
|
timeout = 2
|
2016-04-15 06:04:42 +00:00
|
|
|
until executor.completed_task_count == executor.scheduled_task_count
|
|
|
|
sleep 0.1
|
2016-09-19 09:29:23 +00:00
|
|
|
timeout -= 0.1
|
|
|
|
raise "Executor could not complete all tasks in 2 seconds" unless timeout > 0
|
2016-04-15 06:04:42 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-02 00:50:19 +00:00
|
|
|
end
|
2019-03-24 17:59:28 +00:00
|
|
|
|
|
|
|
require_relative "../../tools/test_common"
|