Module: Anyt::Cli

Defined in:
lib/anyt/cli.rb

Overview

:nodoc:

Constant Summary collapse

DUMMY_ROOT =
::File.expand_path(
  "config.ru",
  ::File.join(::File.dirname(__FILE__), "dummy")
)
RAILS_COMMAND =
"bundle exec puma #{DUMMY_ROOT} -t #{ENV.fetch("RAILS_MAX_THREADS", 5)}"

Class Method Summary collapse

Class Method Details

.run(args = ARGV) ⇒ Object

CLI entrypoint



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/anyt/cli.rb', line 25

def run(args = ARGV)
  parse_options!(args)

  ActionCable.server.config.logger = Rails.logger = AnyCable.logger

  result = 1

  $stdout.puts "Starting AnyT v#{Anyt::VERSION} (pid: #{Process.pid})\n"

  begin
    # "Enable" AnyCable as early as possible to activate all the features in tests
    unless Anyt.config.use_action_cable
      ActionCable.server.config.cable = {"adapter" => "any_cable"}
      require "anycable-rails"
    end

    # Load all test scenarios
    Tests.load_tests unless @skip_tests

    Rails.application.initialize!

    # Start RPC server (unless specified otherwise, e.g. when
    # we want to test Action Cable itself)
    unless @skip_rpc
      http_rpc = AnyCable.config.http_rpc_mount_path.present?

      @rpc_command =
        if http_rpc
          Command.new(RAILS_COMMAND)
        else
          RPC.new
        end

      @rpc_command.start

      if @only_rpc
        if http_rpc
          wait_till_terminated
        else
          @rpc_command.server.wait_till_terminated
        end
        return
      end
    end

    # Start webosocket server under test
    @command = Command.default
    @command.run

    unless @skip_tests
      # Run tests
      result = Tests.run ? 0 : 1
    end

    wait_till_terminated if @only_rails
  rescue Interrupt => e
    $stdout.puts "#{e.message}. Good-bye!"
  ensure
    @rpc_command&.stop unless @skip_rpc
    @command&.stop
  end

  result
end