anyt 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f49015d1bfc782a6cefdc033022683db45e0a8e0885a72aae504a56bdd4a5c1
4
- data.tar.gz: 212fa4ef1c916ea63cbfc2fccc4e974e5a27876a4e963024855f0a333d50f662
3
+ metadata.gz: 9db289698192e906312e6ff3708370e1016b15e2b0299ace6b514f6d5e31adbf
4
+ data.tar.gz: 54cad65181ffa23e5a108c416990610015ffbd1788c5d10a3dfaf1f326f91e09
5
5
  SHA512:
6
- metadata.gz: feddd2dfaf287ac79d775fe8e163582ce8b25357c0d470a4e243a6b849577184444f44437e0cf94028ff478c99bb0bb36cc9bf15d33078f379856dfdba09abb0
7
- data.tar.gz: 195b9d7ed1f1b0e0e9ba876c0e6377f72d56f834154092b1cf586be74b0e9f652da23001bff3ff60d649047de62d3696a1cf7ee72bc33678e8d8a10b21641c2d
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
@@ -97,7 +118,6 @@ module Anyt
97
118
 
98
119
  cli.on("--only-rpc", TrueClass, "Run only RPC server") do |flag|
99
120
  @only_rpc = flag
100
- @skip_tests = true
101
121
  end
102
122
 
103
123
  cli.on("--only-rails", TrueClass, "Run only Rails server") do
@@ -162,11 +182,7 @@ module Anyt
162
182
  end
163
183
 
164
184
  def configure_rails_command!
165
- dummy_path = ::File.expand_path(
166
- "config.ru",
167
- ::File.join(::File.dirname(__FILE__), "dummy")
168
- )
169
- Anyt.config.command = "bundle exec puma #{dummy_path}"
185
+ Anyt.config.command = RAILS_COMMAND
170
186
  Anyt.config.use_action_cable = true
171
187
  end
172
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,6 +68,11 @@ class BenchmarkChannel < ApplicationCable::Channel
63
68
  transmit data
64
69
  end
65
70
 
71
+ def counter(data)
72
+ num = data.fetch("num", 100).to_i
73
+ num.times { ActionCable.server.broadcast "all", {text: "Count: #{_1}"} }
74
+ end
75
+
66
76
  private
67
77
 
68
78
  def stream_id
@@ -70,7 +80,7 @@ class BenchmarkChannel < ApplicationCable::Channel
70
80
  end
71
81
  end
72
82
 
73
- ActionCable.server.config.cable = {"adapter" => "redis"}
83
+ ActionCable.server.config.cable = {"adapter" => ENV.fetch("ACTION_CABLE_ADAPTER", "redis")}
74
84
  ActionCable.server.config.connection_class = -> { ApplicationCable::Connection }
75
85
  ActionCable.server.config.disable_request_forgery_protection = true
76
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.2"
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.2
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-02-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
@@ -278,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
278
  - !ruby/object:Gem::Version
279
279
  version: '0'
280
280
  requirements: []
281
- rubygems_version: 3.4.6
281
+ rubygems_version: 3.4.8
282
282
  signing_key:
283
283
  specification_version: 4
284
284
  summary: Anycable conformance testing tool