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