anycablebility 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f077876a8386fc5b25b4e09109419119223152ec
4
+ data.tar.gz: e4171a66fbba02f2a33f739a06ab760a779ac1e5
5
+ SHA512:
6
+ metadata.gz: b7d5ba72c18db6a575a5ada57009bf0f409f97a38ddb2437442f670b14342b4713f92984b4256b1dc2a9184c8edd825db6af1b7a642bcdc0b2ba4873c9d5778a
7
+ data.tar.gz: 0c7e835680fedbd83e7fdca0afad5877fca3ccf3a8cf96df78bab19c2770f367ab60ce2be03103c9afec97714b11a6780bd51b3a814e57ec02613711a67dc02d
@@ -0,0 +1,42 @@
1
+ # Numerous always-ignore extensions
2
+ *.diff
3
+ *.err
4
+ *.orig
5
+ *.log
6
+ *.rej
7
+ *.swo
8
+ *.swp
9
+ *.vi
10
+ *~
11
+ *.sass-cache
12
+ *.iml
13
+ .idea/
14
+
15
+ # Sublime
16
+ *.sublime-project
17
+ *.sublime-workspace
18
+
19
+ # OS or Editor folders
20
+ .DS_Store
21
+ .cache
22
+ .project
23
+ .settings
24
+ .tmproj
25
+ Thumbs.db
26
+
27
+ .bundle/
28
+ log/*.log
29
+ *.gz
30
+ pkg/
31
+ spec/dummy/db/*.sqlite3
32
+ spec/dummy/db/*.sqlite3-journal
33
+ spec/dummy/tmp/
34
+
35
+ Gemfile.local
36
+ .rspec
37
+ *.gem
38
+ tmp/
39
+ coverage/
40
+
41
+ # ctags tags
42
+ tags
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
@@ -0,0 +1,58 @@
1
+ AllCops:
2
+ # Include gemspec and Rakefile
3
+ Include:
4
+ - 'lib/**/*.rb'
5
+ - 'lib/**/*.rake'
6
+ - 'spec/**/*.rb'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'spec/dummy/**/*'
10
+ - 'tmp/**/*'
11
+ - 'bench/**/*'
12
+ - 'lib/anycable/rpc/**/*'
13
+ DisplayCopNames: true
14
+ StyleGuideCopsOnly: false
15
+ TargetRubyVersion: 2.3
16
+
17
+ Style/AccessorMethodName:
18
+ Enabled: false
19
+
20
+ Style/TrivialAccessors:
21
+ Enabled: false
22
+
23
+ Style/Documentation:
24
+ Exclude:
25
+ - 'spec/**/*.rb'
26
+
27
+ Style/StringLiterals:
28
+ Enabled: true
29
+ EnforcedStyle: double_quotes
30
+
31
+ Style/Documentation:
32
+ Exclude:
33
+ - 'lib/anycablebility/dummy/**/*'
34
+
35
+ Style/SpaceInsideStringInterpolation:
36
+ EnforcedStyle: no_space
37
+
38
+ Style/BlockDelimiters:
39
+ Exclude:
40
+ - 'spec/**/*.rb'
41
+
42
+ Lint/AmbiguousRegexpLiteral:
43
+ Enabled: false
44
+
45
+ Metrics/MethodLength:
46
+ Exclude:
47
+ - 'spec/**/*.rb'
48
+
49
+ Metrics/LineLength:
50
+ Max: 100
51
+ Exclude:
52
+ - 'spec/**/*.rb'
53
+
54
+ Rails/Date:
55
+ Enabled: false
56
+
57
+ Rails/TimeZone:
58
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in anycablebility.gemspec
4
+ gemspec
@@ -0,0 +1,205 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ anycablebility (0.1.0)
5
+ anycable-rails (= 0.4.4)
6
+ concurrent-ruby (~> 1.0.0)
7
+ minitest (~> 5.10.1)
8
+ rack (~> 2)
9
+ rails (~> 5.0)
10
+ websocket (~> 1.2.4)
11
+ websocket-client-simple (~> 0.3.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actioncable (5.0.2)
17
+ actionpack (= 5.0.2)
18
+ nio4r (>= 1.2, < 3.0)
19
+ websocket-driver (~> 0.6.1)
20
+ actionmailer (5.0.2)
21
+ actionpack (= 5.0.2)
22
+ actionview (= 5.0.2)
23
+ activejob (= 5.0.2)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (5.0.2)
27
+ actionview (= 5.0.2)
28
+ activesupport (= 5.0.2)
29
+ rack (~> 2.0)
30
+ rack-test (~> 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
+ actionview (5.0.2)
34
+ activesupport (= 5.0.2)
35
+ builder (~> 3.1)
36
+ erubis (~> 2.7.0)
37
+ rails-dom-testing (~> 2.0)
38
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
39
+ activejob (5.0.2)
40
+ activesupport (= 5.0.2)
41
+ globalid (>= 0.3.6)
42
+ activemodel (5.0.2)
43
+ activesupport (= 5.0.2)
44
+ activerecord (5.0.2)
45
+ activemodel (= 5.0.2)
46
+ activesupport (= 5.0.2)
47
+ arel (~> 7.0)
48
+ activesupport (5.0.2)
49
+ concurrent-ruby (~> 1.0, >= 1.0.2)
50
+ i18n (~> 0.7)
51
+ minitest (~> 5.1)
52
+ tzinfo (~> 1.1)
53
+ addressable (2.5.0)
54
+ public_suffix (~> 2.0, >= 2.0.2)
55
+ anycable (0.4.5)
56
+ anyway_config (~> 0.5.0)
57
+ grpc (~> 1.1.0)
58
+ redis (~> 3.0)
59
+ anycable-rails (0.4.4)
60
+ anycable (~> 0.4.4)
61
+ rails (~> 5)
62
+ anyway_config (0.5.1)
63
+ arel (7.1.4)
64
+ ast (2.3.0)
65
+ builder (3.2.3)
66
+ byebug (9.0.6)
67
+ coderay (1.1.1)
68
+ concurrent-ruby (1.0.5)
69
+ docile (1.1.5)
70
+ erubis (2.7.0)
71
+ event_emitter (0.2.5)
72
+ faraday (0.11.0)
73
+ multipart-post (>= 1.2, < 3)
74
+ globalid (0.3.7)
75
+ activesupport (>= 4.1.0)
76
+ google-protobuf (3.2.0.2)
77
+ googleauth (0.5.1)
78
+ faraday (~> 0.9)
79
+ jwt (~> 1.4)
80
+ logging (~> 2.0)
81
+ memoist (~> 0.12)
82
+ multi_json (~> 1.11)
83
+ os (~> 0.9)
84
+ signet (~> 0.7)
85
+ grpc (1.1.2)
86
+ google-protobuf (~> 3.1)
87
+ googleauth (~> 0.5.1)
88
+ i18n (0.8.1)
89
+ json (2.0.3)
90
+ jwt (1.5.6)
91
+ little-plugger (1.1.4)
92
+ logging (2.2.0)
93
+ little-plugger (~> 1.1)
94
+ multi_json (~> 1.10)
95
+ loofah (2.0.3)
96
+ nokogiri (>= 1.5.9)
97
+ mail (2.6.4)
98
+ mime-types (>= 1.16, < 4)
99
+ memoist (0.15.0)
100
+ method_source (0.8.2)
101
+ mime-types (3.1)
102
+ mime-types-data (~> 3.2015)
103
+ mime-types-data (3.2016.0521)
104
+ mini_portile2 (2.1.0)
105
+ minitest (5.10.1)
106
+ multi_json (1.12.1)
107
+ multipart-post (2.0.0)
108
+ nio4r (2.0.0)
109
+ nokogiri (1.7.1)
110
+ mini_portile2 (~> 2.1.0)
111
+ os (0.9.6)
112
+ parser (2.4.0.0)
113
+ ast (~> 2.2)
114
+ powerpack (0.1.1)
115
+ pry (0.10.4)
116
+ coderay (~> 1.1.0)
117
+ method_source (~> 0.8.1)
118
+ slop (~> 3.4)
119
+ pry-byebug (3.4.2)
120
+ byebug (~> 9.0)
121
+ pry (~> 0.10)
122
+ public_suffix (2.0.5)
123
+ puma (3.8.2)
124
+ rack (2.0.1)
125
+ rack-test (0.6.3)
126
+ rack (>= 1.0)
127
+ rails (5.0.2)
128
+ actioncable (= 5.0.2)
129
+ actionmailer (= 5.0.2)
130
+ actionpack (= 5.0.2)
131
+ actionview (= 5.0.2)
132
+ activejob (= 5.0.2)
133
+ activemodel (= 5.0.2)
134
+ activerecord (= 5.0.2)
135
+ activesupport (= 5.0.2)
136
+ bundler (>= 1.3.0, < 2.0)
137
+ railties (= 5.0.2)
138
+ sprockets-rails (>= 2.0.0)
139
+ rails-dom-testing (2.0.2)
140
+ activesupport (>= 4.2.0, < 6.0)
141
+ nokogiri (~> 1.6)
142
+ rails-html-sanitizer (1.0.3)
143
+ loofah (~> 2.0)
144
+ railties (5.0.2)
145
+ actionpack (= 5.0.2)
146
+ activesupport (= 5.0.2)
147
+ method_source
148
+ rake (>= 0.8.7)
149
+ thor (>= 0.18.1, < 2.0)
150
+ rainbow (2.2.1)
151
+ rake (10.5.0)
152
+ redis (3.3.3)
153
+ rubocop (0.47.1)
154
+ parser (>= 2.3.3.1, < 3.0)
155
+ powerpack (~> 0.1)
156
+ rainbow (>= 1.99.1, < 3.0)
157
+ ruby-progressbar (~> 1.7)
158
+ unicode-display_width (~> 1.0, >= 1.0.1)
159
+ ruby-progressbar (1.8.1)
160
+ signet (0.7.3)
161
+ addressable (~> 2.3)
162
+ faraday (~> 0.9)
163
+ jwt (~> 1.5)
164
+ multi_json (~> 1.10)
165
+ simplecov (0.13.0)
166
+ docile (~> 1.1.0)
167
+ json (>= 1.8, < 3)
168
+ simplecov-html (~> 0.10.0)
169
+ simplecov-html (0.10.0)
170
+ slop (3.6.0)
171
+ sprockets (3.7.1)
172
+ concurrent-ruby (~> 1.0)
173
+ rack (> 1, < 3)
174
+ sprockets-rails (3.2.0)
175
+ actionpack (>= 4.0)
176
+ activesupport (>= 4.0)
177
+ sprockets (>= 3.0.0)
178
+ thor (0.19.4)
179
+ thread_safe (0.3.6)
180
+ tzinfo (1.2.3)
181
+ thread_safe (~> 0.1)
182
+ unicode-display_width (1.1.3)
183
+ websocket (1.2.4)
184
+ websocket-client-simple (0.3.0)
185
+ event_emitter
186
+ websocket
187
+ websocket-driver (0.6.5)
188
+ websocket-extensions (>= 0.1.0)
189
+ websocket-extensions (0.1.2)
190
+
191
+ PLATFORMS
192
+ ruby
193
+
194
+ DEPENDENCIES
195
+ anycablebility!
196
+ bundler (~> 1)
197
+ pry (~> 0.10.4)
198
+ pry-byebug
199
+ puma (~> 3.6)
200
+ rake (~> 10.0)
201
+ rubocop (~> 0.47.1)
202
+ simplecov (>= 0.3.8)
203
+
204
+ BUNDLED WITH
205
+ 1.14.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 palkan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright 2016 palkan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ lint:
2
+ bundler exec rubocop
3
+
4
+ test:
5
+ bin/anycablebility -c "bundle exec puma lib/anycablebility/dummy/config.ru" --skip-rpc
@@ -0,0 +1,35 @@
1
+ [![Circle CI](https://circleci.com/gh/anycable/anycablebility/tree/master.svg?style=svg)](https://circleci.com/gh/anycable/anycablebility/tree/master)<a href="https://gitter.im/anycable/anycablebility"><img src="https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg" alt="Gitter"></a>
2
+
3
+ # Anycable Conformance Testing Tool
4
+
5
+ Anycablebility is a command-line tool to test your [AnyCable](http://anycable.io)-compatible WebSocket servers.
6
+ It contains a set of tests to determine which features are supported by the implementation under consideration.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ gem install anycablebility
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ You should provide a command to run the server and the target URL for WebSocket clients:
17
+
18
+ ```sh
19
+ anycablebility -c "anycable-go" --target-url="ws://localhost:8080/cable"
20
+ ```
21
+
22
+ By default it launches gRPC server on `localhost:50051` and use local Redis instance for broadcasts (`localhost:6379`).
23
+
24
+ For more options run:
25
+
26
+ ```sh
27
+ anycablebility -h
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/anycable/anycablebility/issues.
33
+
34
+ ## License
35
+ The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |config|
5
+ config.libs << ['spec', 'lib']
6
+ config.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+ desc 'Run test'
9
+
10
+ task default: :test
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'anycablebility/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "anycablebility"
10
+ spec.version = Anycablebility::VERSION
11
+ spec.authors = ["palkan"]
12
+ spec.email = ["dementiev.vm@gmail.com"]
13
+
14
+ spec.summary = %q{Anycable conformance testing tool}
15
+ spec.description = %q{Anycable conformance testing tool}
16
+ spec.homepage = "http://github.com/anycable/anycablebility"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.executables << 'anycablebility'
23
+
24
+ spec.add_dependency "rack", "~> 2"
25
+ spec.add_dependency "minitest", "~> 5.10.1"
26
+ spec.add_dependency "rails", "~> 5.0"
27
+ spec.add_dependency "anycable-rails", "0.4.4"
28
+ spec.add_dependency "websocket", "~> 1.2.4"
29
+ spec.add_dependency "websocket-client-simple", "~> 0.3.0"
30
+ spec.add_dependency "concurrent-ruby", "~> 1.0.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "simplecov", ">= 0.3.8"
35
+ spec.add_development_dependency "rubocop", "~> 0.47.1"
36
+ spec.add_development_dependency "pry", "~> 0.10.4"
37
+ spec.add_development_dependency "puma", "~> 3.6"
38
+ spec.add_development_dependency "pry-byebug"
39
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'anycablebility'
6
+ require 'anycablebility/cli'
7
+
8
+ begin
9
+ exit_code = Anycablebility::Cli.run
10
+ rescue => e
11
+ puts 'Bummer! There is an error:'
12
+ puts e
13
+ exit 1
14
+ end
15
+
16
+ exit exit_code
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'anycablebility'
5
+ require 'irb'
6
+
7
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.0
4
+
5
+ dependencies:
6
+ pre:
7
+ - gem install bundler -v 1.11.2
8
+
9
+ test:
10
+ post:
11
+ - make test
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anycablebility/version"
4
+ require "anycablebility/config"
5
+ require "anycablebility/utils"
6
+
7
+ # Anycable conformance testing tool
8
+ module Anycablebility
9
+ class << self
10
+ def config
11
+ @config ||= Config.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "optparse"
5
+
6
+ require "anycablebility/rpc"
7
+ require "anycablebility/command"
8
+ require "anycablebility/tests"
9
+
10
+ module Anycablebility
11
+ module Cli # :nodoc:
12
+ class << self
13
+ # CLI entrypoint
14
+ def run
15
+ parse_options!
16
+
17
+ ActionCable.server.config.logger = Rails.logger = Anycable.logger
18
+
19
+ # Start RPC server (unless specified otherwise, e.g. when
20
+ # we want to test Action Cable itself)
21
+ RPC.start unless @skip_rpc
22
+
23
+ # Start webosocket server under test
24
+ Command.run
25
+
26
+ # Run tests
27
+ Tests.run ? 0 : 1
28
+ ensure
29
+ RPC.stop unless @skip_rpc
30
+ Command.stop
31
+ end
32
+
33
+ private
34
+
35
+ # rubocop: disable Metrics/AbcSize
36
+ # rubocop: disable Metrics/MethodLength
37
+ # rubocop: disable Metrics/BlockLength
38
+ def parse_options!
39
+ parser =
40
+ OptionParser.new do |cli|
41
+ cli.banner = <<~BANNER
42
+ Anycablebility – AnyCable websocket server conformance tool.
43
+
44
+ Usage: anycablebility [options]
45
+
46
+ Options:
47
+ BANNER
48
+
49
+ cli.on("-cCOMMAND", "--command=COMMAND", "Command to run WS server.") do |command|
50
+ Anycablebility.config.command = command
51
+ end
52
+
53
+ cli.on("--target-url=TARGET", "URL of target WebSocket server to test.") do |target|
54
+ Anycablebility.config.target_url = target
55
+ end
56
+
57
+ cli.on("--redis-url=REDIS_URL", "Redis server URL.") do |redis|
58
+ Anycable.config.redis_url = redis
59
+ end
60
+
61
+ cli.on("--skip-rpc", TrueClass, "Do not run RPC server") do |flag|
62
+ @skip_rpc = flag
63
+ end
64
+
65
+ cli.on("--wait-command=TIMEOUT", Integer,
66
+ "Number of seconds to wait for WS server initialization") do |timeout|
67
+ Anycablebility.config.wait_command = timeout
68
+ end
69
+
70
+ cli.on("--debug", "Enable debug mode.") do
71
+ Anycable.config.debug = true
72
+ end
73
+
74
+ cli.on("-h", "--help", "Show this message.") do
75
+ puts cli
76
+ exit
77
+ end
78
+
79
+ cli.on("--version", "Print version.") do
80
+ puts Anycablebility::VERSION
81
+ exit
82
+ end
83
+ end
84
+
85
+ parser.parse!
86
+ rescue OptionParser::InvalidOption => e
87
+ unknown_option = e.args.first
88
+ puts "This option looks unfamiliar: #{unknown_option}. A typo?"
89
+ puts "Use `anycablebility --help` to list all available options."
90
+ exit 1
91
+ end
92
+ # rubocop: enable Metrics/AbcSize
93
+ # rubocop: enable Metrics/MethodLength
94
+ # rubocop: enable Metrics/BlockLength
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Synchronous websocket client
4
+ # Based on https://github.com/rails/rails/blob/v5.0.1/actioncable/test/client_test.rb
5
+ class Client
6
+ require "websocket-client-simple"
7
+ require "concurrent"
8
+
9
+ WAIT_WHEN_EXPECTING_EVENT = 15
10
+ WAIT_WHEN_NOT_EXPECTING_EVENT = 0.5
11
+
12
+ # rubocop: disable Metrics/AbcSize
13
+ # rubocop: disable Metrics/MethodLength
14
+ def initialize(ignore: [], url: Anycablebility.config.target_url, cookies: "")
15
+ ignore_message_types = @ignore_message_types = ignore
16
+ messages = @messages = Queue.new
17
+ closed = @closed = Concurrent::Event.new
18
+ has_messages = @has_messages = Concurrent::Semaphore.new(0)
19
+
20
+ open = Concurrent::Promise.new
21
+
22
+ @ws = WebSocket::Client::Simple.connect(
23
+ url,
24
+ headers: {
25
+ "COOKIE" => cookies
26
+ }
27
+ ) do |ws|
28
+ ws.on(:error) do |event|
29
+ event = RuntimeError.new(event.message) unless event.is_a?(Exception)
30
+
31
+ if open.pending?
32
+ open.fail(event)
33
+ else
34
+ messages << event
35
+ has_messages.release
36
+ end
37
+ end
38
+
39
+ ws.on(:open) do |_event|
40
+ open.set(true)
41
+ end
42
+
43
+ ws.on(:message) do |event|
44
+ if event.type == :close
45
+ closed.set
46
+ else
47
+ message = JSON.parse(event.data)
48
+
49
+ next if ignore_message_types.include?(message["type"])
50
+ messages << message
51
+ has_messages.release
52
+ end
53
+ end
54
+
55
+ ws.on(:close) do |_event|
56
+ closed.set
57
+ end
58
+ end
59
+
60
+ open.wait!(WAIT_WHEN_EXPECTING_EVENT)
61
+ end
62
+ # rubocop: enable Metrics/AbcSize
63
+ # rubocop: enable Metrics/MethodLength
64
+
65
+ def receive
66
+ raise "Timed out to receive message" unless
67
+ @has_messages.try_acquire(1, WAIT_WHEN_EXPECTING_EVENT)
68
+
69
+ msg = @messages.pop(true)
70
+ raise msg if msg.is_a?(Exception)
71
+
72
+ msg
73
+ end
74
+
75
+ def send(message)
76
+ @ws.send(JSON.generate(message))
77
+ end
78
+
79
+ def close
80
+ sleep WAIT_WHEN_NOT_EXPECTING_EVENT
81
+
82
+ raise "#{@messages.size} messages unprocessed" unless @messages.empty?
83
+
84
+ @ws.close
85
+ wait_for_close
86
+ end
87
+
88
+ def wait_for_close
89
+ @closed.wait(WAIT_WHEN_EXPECTING_EVENT)
90
+ end
91
+
92
+ def closed?
93
+ @closed.set?
94
+ end
95
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anycablebility
4
+ # Runs system command (websocket server)
5
+ module Command
6
+ class << self
7
+ attr_accessor :running
8
+
9
+ # rubocop: disable Metrics/MethodLength
10
+ def run
11
+ return if @running
12
+
13
+ Anycable.logger.debug "Running command: #{Anycablebility.config.command}"
14
+
15
+ out = Anycable.config.debug ? STDOUT : IO::NULL
16
+
17
+ @pid = Process.spawn(
18
+ Anycablebility.config.command,
19
+ out: out,
20
+ err: out
21
+ )
22
+
23
+ Process.detach(@pid)
24
+
25
+ Anycable.logger.debug "Command PID: #{@pid}"
26
+
27
+ @running = true
28
+
29
+ sleep Anycablebility.config.wait_command
30
+ end
31
+ # rubocop: enable Metrics/MethodLength
32
+
33
+ def stop
34
+ return unless @running
35
+
36
+ Anycable.logger.debug "Terminate PID: #{@pid}"
37
+
38
+ Process.kill("SIGKILL", @pid)
39
+
40
+ @running = false
41
+ end
42
+
43
+ def running?
44
+ @running == true
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require "anyway"
3
+
4
+ module Anycablebility
5
+ # Anycablebility configuration
6
+ class Config < Anyway::Config
7
+ attr_config :command,
8
+ target_url: "ws://localhost:9292/",
9
+ wait_command: 2
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "action_cable"
5
+
6
+ module ApplicationCable
7
+ class Connection < ActionCable::Connection::Base
8
+ end
9
+ end
10
+
11
+ module ApplicationCable
12
+ class Channel < ActionCable::Channel::Base
13
+ end
14
+ end
15
+
16
+ pattern = File.expand_path("channels/**/*.rb", __dir__)
17
+
18
+ Dir.glob(pattern).each { |file| require file }
19
+
20
+ ActionCable.server.config.connection_class = -> { ApplicationCable::Connection }
21
+ ActionCable.server.config.disable_request_forgery_protection = true
22
+ ActionCable.server.config.logger = Rails.logger = Logger.new(STDOUT)
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class JustChannel < ApplicationCable::Channel
4
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TransmitSubscriptionChannel < ApplicationCable::Channel
4
+ def subscribed
5
+ transmit("hello")
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./application"
4
+
5
+ run ActionCable.server
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anycablebility # :nodoc:
4
+ require "anycablebility/dummy/application"
5
+ require "anycable-rails"
6
+
7
+ # Runs AnyCable RPC server in the background
8
+ module RPC
9
+ using AsyncHelpers
10
+
11
+ class << self
12
+ attr_accessor :running
13
+
14
+ def start
15
+ Anycable.logger.debug "Starting RPC server ..."
16
+
17
+ @thread = Thread.new { Anycable::Server.start }
18
+ @thread.abort_on_exception = true
19
+
20
+ wait(2) { running? }
21
+
22
+ Anycable.logger.debug "RPC server started"
23
+ end
24
+
25
+ def stop
26
+ return unless running?
27
+
28
+ Anycable::Server.grpc_server.stop
29
+ end
30
+
31
+ def running?
32
+ Anycable::Server.grpc_server&.running_state == :running
33
+ end
34
+ end
35
+
36
+ Anycable.configure do |config|
37
+ config.connection_factory = ActionCable.server.config.connection_class.call
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anycablebility
4
+ # Loads and runs test cases
5
+ module Tests
6
+ require "anycablebility/client"
7
+ require "minitest/spec"
8
+ require "minitest/hell"
9
+
10
+ class << self
11
+ def run
12
+ load_tests
13
+ MiniTest.run
14
+ end
15
+
16
+ private
17
+
18
+ def load_tests
19
+ pattern = File.expand_path("tests/**/*.rb", __dir__)
20
+ Dir.glob(pattern).each { |file| require file }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ describe "Basic subscription" do
3
+ before do
4
+ @client = Client.new(ignore: %w(ping welcome))
5
+ end
6
+
7
+ it "receives confirmation" do
8
+ channel = "JustChannel"
9
+
10
+ subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
11
+
12
+ @client.send(subscribe_request)
13
+
14
+ subscription_confirmation = {
15
+ "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
16
+ }
17
+
18
+ assert_equal subscription_confirmation, @client.receive
19
+ end
20
+
21
+ it "receives transmission" do
22
+ channel = "TransmitSubscriptionChannel"
23
+
24
+ subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
25
+
26
+ @client.send(subscribe_request)
27
+
28
+ transmission = { "identifier" => { channel: channel }.to_json, "message" => "hello" }
29
+
30
+ assert_equal transmission, @client.receive
31
+
32
+ subscription_confirmation = {
33
+ "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
34
+ }
35
+
36
+ assert_equal subscription_confirmation, @client.receive
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ describe "Ping message" do
3
+ it "receives pings timestamps after connect" do
4
+ client = Client.new(ignore: ["welcome"])
5
+
6
+ previous_stamp = 0
7
+
8
+ 2.times do
9
+ ping = client.receive
10
+
11
+ current_stamp = ping["message"]
12
+
13
+ assert_equal ping["type"], "ping"
14
+ assert_kind_of Integer, current_stamp
15
+ refute_operator previous_stamp, :>=, current_stamp
16
+
17
+ previous_stamp = current_stamp
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ describe "Welcome message" do
3
+ it "receives welcome on connect" do
4
+ client = Client.new
5
+ assert_equal client.receive, "type" => "welcome"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anycablebility/utils/async_helpers"
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anycablebility
4
+ module AsyncHelpers # :nodoc:
5
+ refine Object do
6
+ # Wait for block to return true of raise error
7
+ def wait(timeout = 1)
8
+ until yield
9
+ sleep 0.1
10
+ timeout -= 0.1
11
+ raise "Timeout error" unless timeout.positive?
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anycablebility
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,273 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anycablebility
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - palkan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.10.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.10.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: anycable-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: websocket
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: websocket-client-simple
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.3.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: concurrent-ruby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 0.3.8
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.3.8
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.47.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.47.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.10.4
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.10.4
181
+ - !ruby/object:Gem::Dependency
182
+ name: puma
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '3.6'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '3.6'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry-byebug
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description: Anycable conformance testing tool
210
+ email:
211
+ - dementiev.vm@gmail.com
212
+ executables:
213
+ - anycablebility
214
+ extensions: []
215
+ extra_rdoc_files: []
216
+ files:
217
+ - ".gitignore"
218
+ - ".hound.yml"
219
+ - ".rubocop.yml"
220
+ - Gemfile
221
+ - Gemfile.lock
222
+ - LICENSE.txt
223
+ - MIT-LICENSE
224
+ - Makefile
225
+ - README.md
226
+ - Rakefile
227
+ - anycablebility.gemspec
228
+ - bin/anycablebility
229
+ - bin/console
230
+ - bin/setup
231
+ - circle.yml
232
+ - lib/anycablebility.rb
233
+ - lib/anycablebility/cli.rb
234
+ - lib/anycablebility/client.rb
235
+ - lib/anycablebility/command.rb
236
+ - lib/anycablebility/config.rb
237
+ - lib/anycablebility/dummy/application.rb
238
+ - lib/anycablebility/dummy/channels/just_channel.rb
239
+ - lib/anycablebility/dummy/channels/transmit_subscription_channel.rb
240
+ - lib/anycablebility/dummy/config.ru
241
+ - lib/anycablebility/rpc.rb
242
+ - lib/anycablebility/tests.rb
243
+ - lib/anycablebility/tests/basic_subscription_test.rb
244
+ - lib/anycablebility/tests/pings_test.rb
245
+ - lib/anycablebility/tests/welcome_test.rb
246
+ - lib/anycablebility/utils.rb
247
+ - lib/anycablebility/utils/async_helpers.rb
248
+ - lib/anycablebility/version.rb
249
+ homepage: http://github.com/anycable/anycablebility
250
+ licenses:
251
+ - MIT
252
+ metadata: {}
253
+ post_install_message:
254
+ rdoc_options: []
255
+ require_paths:
256
+ - lib
257
+ required_ruby_version: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ">="
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ required_rubygems_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: '0'
267
+ requirements: []
268
+ rubyforge_project:
269
+ rubygems_version: 2.6.11
270
+ signing_key:
271
+ specification_version: 4
272
+ summary: Anycable conformance testing tool
273
+ test_files: []