anyt 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98e0ff916d9b26a1c59c1590deaf1991e5b03e9307d9939069d2a7f16360c8a5
4
- data.tar.gz: 8e425053f5af7706d9a3ea478d6b08e43ef6b7fe15f58fa0c97800c6aafcaff8
3
+ metadata.gz: 9db289698192e906312e6ff3708370e1016b15e2b0299ace6b514f6d5e31adbf
4
+ data.tar.gz: 54cad65181ffa23e5a108c416990610015ffbd1788c5d10a3dfaf1f326f91e09
5
5
  SHA512:
6
- metadata.gz: ef09aae331254a361fe2f62d5f0d00bcac7c1f353c90f88f225cbff3d3e16b145e1225c28d026c3aabe5bac01bcef52944f6a5a4846d48ff4f0ff0841d5ae1ac
7
- data.tar.gz: 06ecdbdf18997b6ed3e7e4d13a8a68069b35bcd1db124c27cbcb11c739e68abbd7e168b655cf0b1c366d3ab0d72b6e9d65394472c5135e9b31d25790e13124a7
6
+ metadata.gz: fea80bb2f253a3787ccdd27e37f5ba0b8ca93fbcc48d375c3ec3698d9e48138da8b137a0ceb95a0cced5c9f880562cd98cdb5e2d40cebdf3fd22335432cff5f3
7
+ data.tar.gz: cfa930d46971b56a14d2f28821e642f02425c74a4e0ddc2dfabdb71ae3f29e1da6fd0148cd94c905c92d60fe06ed360cdc938b2ef93c8a30c7d1621d8e322f58
data/lib/anyt/cli.rb CHANGED
@@ -13,6 +13,13 @@ $stdout.sync = true
13
13
 
14
14
  module Anyt
15
15
  module Cli # :nodoc:
16
+ DUMMY_ROOT = ::File.expand_path(
17
+ "config.ru",
18
+ ::File.join(::File.dirname(__FILE__), "dummy")
19
+ )
20
+
21
+ RAILS_COMMAND = "bundle exec puma #{DUMMY_ROOT} -t #{ENV.fetch("RAILS_MAX_THREADS", 5)}"
22
+
16
23
  class << self
17
24
  # CLI entrypoint
18
25
  def run(args = ARGV)
@@ -39,16 +46,30 @@ module Anyt
39
46
  # Start RPC server (unless specified otherwise, e.g. when
40
47
  # we want to test Action Cable itself)
41
48
  unless @skip_rpc
42
- RPC.start
49
+ http_rpc = AnyCable.config.http_rpc_mount_path.present?
50
+
51
+ @rpc_command =
52
+ if http_rpc
53
+ Command.new(RAILS_COMMAND)
54
+ else
55
+ RPC.new
56
+ end
57
+
58
+ @rpc_command.start
43
59
 
44
60
  if @only_rpc
45
- RPC.server.wait_till_terminated
61
+ if http_rpc
62
+ wait_till_terminated
63
+ else
64
+ @rpc_command.server.wait_till_terminated
65
+ end
46
66
  return
47
67
  end
48
68
  end
49
69
 
50
70
  # Start webosocket server under test
51
- Command.run
71
+ @command = Command.default
72
+ @command.run
52
73
 
53
74
  unless @skip_tests
54
75
  # Run tests
@@ -59,8 +80,8 @@ module Anyt
59
80
  rescue Interrupt => e
60
81
  $stdout.puts "#{e.message}. Good-bye!"
61
82
  ensure
62
- RPC.stop unless @skip_rpc
63
- Command.stop
83
+ @rpc_command&.stop unless @skip_rpc
84
+ @command&.stop
64
85
  end
65
86
 
66
87
  result
@@ -161,11 +182,7 @@ module Anyt
161
182
  end
162
183
 
163
184
  def configure_rails_command!
164
- dummy_path = ::File.expand_path(
165
- "config.ru",
166
- ::File.join(::File.dirname(__FILE__), "dummy")
167
- )
168
- Anyt.config.command = "bundle exec puma #{dummy_path}"
185
+ Anyt.config.command = RAILS_COMMAND
169
186
  Anyt.config.use_action_cable = true
170
187
  end
171
188
 
data/lib/anyt/command.rb CHANGED
@@ -4,60 +4,80 @@ require "childprocess"
4
4
 
5
5
  module Anyt
6
6
  # Runs system command (websocket server)
7
- module Command
7
+ class Command
8
8
  class << self
9
- def run
10
- return if running?
9
+ attr_reader :instance
11
10
 
12
- return unless Anyt.config.command
11
+ def default
12
+ @instance ||= new
13
+ end
13
14
 
14
- AnyCable.logger.debug "Running command: #{Anyt.config.command}"
15
+ def restart
16
+ instance&.restart
17
+ end
18
+ end
15
19
 
16
- @process = ChildProcess.build(*Anyt.config.command.split(/\s+/))
20
+ attr_reader :cmd
17
21
 
18
- process.io.inherit! if AnyCable.config.debug
22
+ def initialize(cmd = Anyt.config.command)
23
+ @cmd = cmd
24
+ end
19
25
 
20
- process.detach = true
26
+ def run
27
+ return if running?
21
28
 
22
- process.environment["ANYCABLE_DEBUG"] = "1" if AnyCable.config.debug?
23
- process.environment["ANYT_REMOTE_CONTROL_PORT"] = Anyt.config.remote_control_port
29
+ return unless cmd
24
30
 
25
- process.start
31
+ AnyCable.logger.debug "Running command: #{cmd}"
26
32
 
27
- AnyCable.logger.debug "Command PID: #{process.pid}"
33
+ @process = ChildProcess.build(*cmd.split(/\s+/))
28
34
 
29
- sleep Anyt.config.wait_command
30
- raise "Command failed to start" unless running?
31
- end
32
- # rubocop: enable Metrics/MethodLength
33
- # rubocop: enable Metrics/AbcSize
35
+ process.io.inherit! if AnyCable.config.debug
34
36
 
35
- def restart
36
- return unless running?
37
+ process.detach = true
37
38
 
38
- AnyCable.logger.debug "Restarting command PID: #{process.pid}"
39
+ process.environment["ANYCABLE_DEBUG"] = "1" if AnyCable.config.debug?
40
+ process.environment["ANYT_REMOTE_CONTROL_PORT"] = Anyt.config.remote_control_port
41
+ process.environment["ACTION_CABLE_ADAPTER"] = "any_cable" unless Anyt.config.use_action_cable
39
42
 
40
- stop
41
- process.wait
43
+ process.start
42
44
 
43
- run
44
- end
45
+ AnyCable.logger.debug "Command PID: #{process.pid}"
45
46
 
46
- def stop
47
- return unless running?
47
+ sleep Anyt.config.wait_command
48
+ raise "Command failed to start" unless running?
49
+ end
48
50
 
49
- AnyCable.logger.debug "Terminate PID: #{process.pid}"
51
+ alias_method :start, :run
50
52
 
51
- process.stop
52
- end
53
+ # rubocop: enable Metrics/MethodLength
54
+ # rubocop: enable Metrics/AbcSize
53
55
 
54
- def running?
55
- process&.alive?
56
- end
56
+ def restart
57
+ return unless running?
58
+
59
+ AnyCable.logger.debug "Restarting command PID: #{process.pid}"
60
+
61
+ stop
62
+ process.wait
63
+
64
+ run
65
+ end
57
66
 
58
- private
67
+ def stop
68
+ return unless running?
59
69
 
60
- attr_reader :process
70
+ AnyCable.logger.debug "Terminate PID: #{process.pid}"
71
+
72
+ process.stop
73
+ end
74
+
75
+ def running?
76
+ process&.alive?
61
77
  end
78
+
79
+ private
80
+
81
+ attr_reader :process
62
82
  end
63
83
  end
data/lib/anyt/config.rb CHANGED
@@ -29,8 +29,8 @@ module Anyt
29
29
  end
30
30
 
31
31
  def tests_filter
32
- only_rxp = /(#{only_tests.join('|')})/ if only_tests
33
- except_rxp = /(#{except_tests.join('|')})/ if except_tests
32
+ only_rxp = /(#{only_tests.join("|")})/ if only_tests
33
+ except_rxp = /(#{except_tests.join("|")})/ if except_tests
34
34
 
35
35
  @tests_filter ||= lambda do |path|
36
36
  (only_rxp.nil? || only_rxp.match?(path)) &&
@@ -20,6 +20,8 @@ class TestApp < Rails::Application
20
20
  config.paths["config/routes.rb"] << File.join(__dir__, "routes.rb")
21
21
  end
22
22
 
23
+ DISCONNECT_DELAY = ENV["ANYCABLE_DISCONNECT_DELAY"].to_f
24
+
23
25
  module ApplicationCable
24
26
  class Connection < ActionCable::Connection::Base
25
27
  delegate :params, to: :request
@@ -32,6 +34,9 @@ module ApplicationCable
32
34
  end
33
35
 
34
36
  def disconnect
37
+ if DISCONNECT_DELAY > 0
38
+ sleep DISCONNECT_DELAY
39
+ end
35
40
  logger.debug "Disconnected"
36
41
  end
37
42
  end
@@ -63,7 +68,6 @@ class BenchmarkChannel < ApplicationCable::Channel
63
68
  transmit data
64
69
  end
65
70
 
66
-
67
71
  def counter(data)
68
72
  num = data.fetch("num", 100).to_i
69
73
  num.times { ActionCable.server.broadcast "all", {text: "Count: #{_1}"} }
@@ -76,7 +80,7 @@ class BenchmarkChannel < ApplicationCable::Channel
76
80
  end
77
81
  end
78
82
 
79
- ActionCable.server.config.cable = {"adapter" => "redis"}
83
+ ActionCable.server.config.cable = {"adapter" => ENV.fetch("ACTION_CABLE_ADAPTER", "redis")}
80
84
  ActionCable.server.config.connection_class = -> { ApplicationCable::Connection }
81
85
  ActionCable.server.config.disable_request_forgery_protection = true
82
86
  ActionCable.server.config.logger =
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./application"
3
+ require_relative "application"
4
4
 
5
5
  require_relative "../tests"
6
6
  require_relative "../remote_control"
@@ -2,6 +2,7 @@
2
2
 
3
3
  ENV["TERM"] = "#{ENV["TERM"]}color" unless ENV["TERM"]&.match?(/color/)
4
4
  require "minitest/spec"
5
+ require "minitest/unit"
5
6
  require "minitest/reporters"
6
7
 
7
8
  module Anyt
data/lib/anyt/rpc.rb CHANGED
@@ -6,38 +6,36 @@ require "redis"
6
6
 
7
7
  module Anyt # :nodoc:
8
8
  # Runs AnyCable RPC server in the background
9
- module RPC
9
+ class RPC
10
10
  using AsyncHelpers
11
11
 
12
- class << self
13
- attr_accessor :running
14
- attr_reader :server
12
+ attr_accessor :running
13
+ attr_reader :server
15
14
 
16
- def start
17
- AnyCable.logger.debug "Starting RPC server ..."
15
+ def start
16
+ AnyCable.logger.debug "Starting RPC server ..."
18
17
 
19
- AnyCable.server_callbacks.each(&:call)
18
+ AnyCable.server_callbacks.each(&:call)
20
19
 
21
- @server = AnyCable::GRPC::Server.new(
22
- host: AnyCable.config.rpc_host,
23
- **AnyCable.config.to_grpc_params
24
- )
20
+ @server = AnyCable::GRPC::Server.new(
21
+ host: AnyCable.config.rpc_host,
22
+ **AnyCable.config.to_grpc_params
23
+ )
25
24
 
26
- if defined?(::AnyCable::Middlewares::EnvSid)
27
- AnyCable.middleware.use(::AnyCable::Middlewares::EnvSid)
28
- end
25
+ if defined?(::AnyCable::Middlewares::EnvSid)
26
+ AnyCable.middleware.use(::AnyCable::Middlewares::EnvSid)
27
+ end
29
28
 
30
- AnyCable.middleware.freeze
29
+ AnyCable.middleware.freeze
31
30
 
32
- server.start
31
+ server.start
33
32
 
34
- AnyCable.logger.debug "RPC server started"
35
- end
36
- # rubocop: enable Metrics/AbcSize,Metrics/MethodLength
33
+ AnyCable.logger.debug "RPC server started"
34
+ end
35
+ # rubocop: enable Metrics/AbcSize,Metrics/MethodLength
37
36
 
38
- def stop
39
- server&.stop
40
- end
37
+ def stop
38
+ server&.stop
41
39
  end
42
40
 
43
41
  AnyCable.connection_factory = ActionCable.server.config.connection_class.call
data/lib/anyt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyt
4
- VERSION = "1.2.3"
4
+ VERSION = "1.2.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-23 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack