anyt 1.0.2 → 1.0.3
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 +4 -4
 - data/lib/anyt/cli.rb +50 -9
 - data/lib/anyt/command.rb +2 -0
 - data/lib/anyt/dummy/application.rb +23 -0
 - data/lib/anyt/tests/features/channel_state_test.rb +7 -5
 - data/lib/anyt/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 42cd66b2a05dcf5d46c060a2a9540c26368fe003f86febfb94c8104a3ccfacc9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e1f8c0cbe88a223d9383f8467e44f75f05ad6d1718c309d19f7d90a102b7f9ad
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 86714f4bfbddf5242491bb371b714becfaffd3353fe275f8badb3839731bcdcfc66b96d2188d9fe4089ca612234edd72243c13c0e0263932337df5758a19eaa9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b3b2af67d98a2542ba05912694f76b052d5a51b4bb3d84159af45aece063faf03242f46065687e765268395fef52d607a7bfc0989918af62b4d2582e46d37020
         
     | 
    
        data/lib/anyt/cli.rb
    CHANGED
    
    | 
         @@ -32,7 +32,7 @@ module Anyt 
     | 
|
| 
       32 
32 
     | 
    
         
             
                      end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                      # Load all test scenarios
         
     | 
| 
       35 
     | 
    
         
            -
                      Tests.load_tests
         
     | 
| 
      
 35 
     | 
    
         
            +
                      Tests.load_tests unless @skip_tests
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                      Rails.application.initialize!
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
         @@ -50,8 +50,14 @@ module Anyt 
     | 
|
| 
       50 
50 
     | 
    
         
             
                      # Start webosocket server under test
         
     | 
| 
       51 
51 
     | 
    
         
             
                      Command.run
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                       
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
                      unless @skip_tests
         
     | 
| 
      
 54 
     | 
    
         
            +
                        # Run tests
         
     | 
| 
      
 55 
     | 
    
         
            +
                        result = Tests.run ? 0 : 1
         
     | 
| 
      
 56 
     | 
    
         
            +
                      end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                      wait_till_terminated if @only_rails
         
     | 
| 
      
 59 
     | 
    
         
            +
                    rescue Interrupt => e
         
     | 
| 
      
 60 
     | 
    
         
            +
                      $stdout.puts "#{e.message}. Good-bye!"
         
     | 
| 
       55 
61 
     | 
    
         
             
                    ensure
         
     | 
| 
       56 
62 
     | 
    
         
             
                      RPC.stop unless @skip_rpc
         
     | 
| 
       57 
63 
     | 
    
         
             
                      Command.stop
         
     | 
| 
         @@ -91,16 +97,21 @@ module Anyt 
     | 
|
| 
       91 
97 
     | 
    
         | 
| 
       92 
98 
     | 
    
         
             
                        cli.on("--only-rpc", TrueClass, "Run only RPC server") do |flag|
         
     | 
| 
       93 
99 
     | 
    
         
             
                          @only_rpc = flag
         
     | 
| 
      
 100 
     | 
    
         
            +
                          @skip_tests = true
         
     | 
| 
      
 101 
     | 
    
         
            +
                        end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                        cli.on("--only-rails", TrueClass, "Run only Rails server") do
         
     | 
| 
      
 104 
     | 
    
         
            +
                          @skip_rpc = true
         
     | 
| 
      
 105 
     | 
    
         
            +
                          @only_rails = true
         
     | 
| 
      
 106 
     | 
    
         
            +
                          @skip_tests = true
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                          configure_rails_command!
         
     | 
| 
       94 
109 
     | 
    
         
             
                        end
         
     | 
| 
       95 
110 
     | 
    
         | 
| 
       96 
111 
     | 
    
         
             
                        cli.on("--self-check", "Run tests again Action Cable itself") do
         
     | 
| 
       97 
112 
     | 
    
         
             
                          @skip_rpc = true
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                            ::File.join(::File.dirname(__FILE__), "dummy")
         
     | 
| 
       101 
     | 
    
         
            -
                          )
         
     | 
| 
       102 
     | 
    
         
            -
                          Anyt.config.command = "bundle exec puma #{dummy_path}"
         
     | 
| 
       103 
     | 
    
         
            -
                          Anyt.config.use_action_cable = true
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                          configure_rails_command!
         
     | 
| 
       104 
115 
     | 
    
         
             
                        end
         
     | 
| 
       105 
116 
     | 
    
         | 
| 
       106 
117 
     | 
    
         
             
                        cli.on("--only test1,test2,test3", Array, "Run only specified tests") do |only_tests|
         
     | 
| 
         @@ -149,6 +160,36 @@ module Anyt 
     | 
|
| 
       149 
160 
     | 
    
         
             
                    puts "Use `anyt --help` to list all available options."
         
     | 
| 
       150 
161 
     | 
    
         
             
                    exit 1
         
     | 
| 
       151 
162 
     | 
    
         
             
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  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}"
         
     | 
| 
      
 170 
     | 
    
         
            +
                    Anyt.config.use_action_cable = true
         
     | 
| 
      
 171 
     | 
    
         
            +
                  end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                  def wait_till_terminated
         
     | 
| 
      
 174 
     | 
    
         
            +
                    self_read = setup_signals
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                    while readable_io = IO.select([self_read]) # rubocop:disable Lint/AssignmentInCondition
         
     | 
| 
      
 177 
     | 
    
         
            +
                      signal = readable_io.first[0].gets.strip
         
     | 
| 
      
 178 
     | 
    
         
            +
                      raise Interrupt, "SIG#{signal} received"
         
     | 
| 
      
 179 
     | 
    
         
            +
                    end
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                  def setup_signals
         
     | 
| 
      
 183 
     | 
    
         
            +
                    self_read, self_write = IO.pipe
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                    %w[INT TERM].each do |signal|
         
     | 
| 
      
 186 
     | 
    
         
            +
                      trap signal do
         
     | 
| 
      
 187 
     | 
    
         
            +
                        self_write.puts signal
         
     | 
| 
      
 188 
     | 
    
         
            +
                      end
         
     | 
| 
      
 189 
     | 
    
         
            +
                    end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                    self_read
         
     | 
| 
      
 192 
     | 
    
         
            +
                  end
         
     | 
| 
       152 
193 
     | 
    
         
             
                end
         
     | 
| 
       153 
194 
     | 
    
         
             
              end
         
     | 
| 
       154 
195 
     | 
    
         
             
            end
         
     | 
    
        data/lib/anyt/command.rb
    CHANGED
    
    | 
         @@ -11,6 +11,8 @@ module Anyt 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  def run
         
     | 
| 
       12 
12 
     | 
    
         
             
                    return if running?
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
      
 14 
     | 
    
         
            +
                    raise "Please, specify command via -c (--command) option" unless Anyt.config.command
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       14 
16 
     | 
    
         
             
                    AnyCable.logger.debug "Running command: #{Anyt.config.command}"
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
       16 
18 
     | 
    
         
             
                    @process = ChildProcess.build(*Anyt.config.command.split(/\s+/))
         
     | 
| 
         @@ -42,6 +42,29 @@ module ApplicationCable 
     | 
|
| 
       42 
42 
     | 
    
         
             
              end
         
     | 
| 
       43 
43 
     | 
    
         
             
            end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
      
 45 
     | 
    
         
            +
            # BenchmarkChannel is useful when running Rails app only or RPC only
         
     | 
| 
      
 46 
     | 
    
         
            +
            class BenchmarkChannel < ApplicationCable::Channel
         
     | 
| 
      
 47 
     | 
    
         
            +
              def subscribed
         
     | 
| 
      
 48 
     | 
    
         
            +
                stream_from "all#{stream_id}"
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def echo(data)
         
     | 
| 
      
 52 
     | 
    
         
            +
                transmit data
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              def broadcast(data)
         
     | 
| 
      
 56 
     | 
    
         
            +
                ActionCable.server.broadcast "all#{stream_id}", data
         
     | 
| 
      
 57 
     | 
    
         
            +
                data["action"] = "broadcastResult"
         
     | 
| 
      
 58 
     | 
    
         
            +
                transmit data
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              private
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
              def stream_id
         
     | 
| 
      
 64 
     | 
    
         
            +
                params[:id] || ""
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
       45 
68 
     | 
    
         
             
            ActionCable.server.config.cable = {"adapter" => "redis"}
         
     | 
| 
       46 
69 
     | 
    
         
             
            ActionCable.server.config.connection_class = -> { ApplicationCable::Connection }
         
     | 
| 
       47 
70 
     | 
    
         
             
            ActionCable.server.config.disable_request_forgery_protection = true
         
     | 
| 
         @@ -17,6 +17,8 @@ feature "Channel state" do 
     | 
|
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                def unsubscribed
         
     | 
| 
      
 20 
     | 
    
         
            +
                  return unless params["notify_disconnect"]
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       20 
22 
     | 
    
         
             
                  ActionCable.server.broadcast("state_counts", data: "user left: #{user[:name]}")
         
     | 
| 
       21 
23 
     | 
    
         
             
                end
         
     | 
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
| 
         @@ -24,7 +26,7 @@ feature "Channel state" do 
     | 
|
| 
       24 
26 
     | 
    
         
             
              let(:identifier) { {channel: channel, name: "chipolino"}.to_json }
         
     | 
| 
       25 
27 
     | 
    
         | 
| 
       26 
28 
     | 
    
         
             
              let(:client2) { build_client(ignore: %w[ping welcome]) }
         
     | 
| 
       27 
     | 
    
         
            -
              let(:identifier2) { {channel: channel, name: "chipollone"}.to_json }
         
     | 
| 
      
 29 
     | 
    
         
            +
              let(:identifier2) { {channel: channel, name: "chipollone", notify_disconnect: true}.to_json }
         
     | 
| 
       28 
30 
     | 
    
         | 
| 
       29 
31 
     | 
    
         
             
              before do
         
     | 
| 
       30 
32 
     | 
    
         
             
                subscribe_request = {command: "subscribe", identifier: identifier}
         
     | 
| 
         @@ -67,13 +69,13 @@ feature "Channel state" do 
     | 
|
| 
       67 
69 
     | 
    
         | 
| 
       68 
70 
     | 
    
         
             
                assert_equal ack, client2.receive
         
     | 
| 
       69 
71 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                 
     | 
| 
      
 72 
     | 
    
         
            +
                client2.close
         
     | 
| 
       71 
73 
     | 
    
         | 
| 
       72 
74 
     | 
    
         
             
                msg = {
         
     | 
| 
       73 
     | 
    
         
            -
                  "identifier" =>  
     | 
| 
       74 
     | 
    
         
            -
                  "message" => {"data" => "user left:  
     | 
| 
      
 75 
     | 
    
         
            +
                  "identifier" => identifier,
         
     | 
| 
      
 76 
     | 
    
         
            +
                  "message" => {"data" => "user left: chipollone"}
         
     | 
| 
       75 
77 
     | 
    
         
             
                }
         
     | 
| 
       76 
78 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
                assert_equal msg,  
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal msg, client.receive
         
     | 
| 
       78 
80 
     | 
    
         
             
              end
         
     | 
| 
       79 
81 
     | 
    
         
             
            end
         
     | 
    
        data/lib/anyt/version.rb
    CHANGED
    
    
    
        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.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - palkan
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-09-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rack
         
     |