Skip to content

Commit

Permalink
Use anycable-rack-server in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jun 25, 2020
1 parent d0b2bf5 commit f711509
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/system_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ jobs:
- name: Run RSpec
run: |
bundle exec rails db:prepare
sudo bundle exec rails g anycable:download --bin-path=./bin
bundle exec rails webpacker:compile
sudo cp ./bin/anycable-go /usr/local/bin/
bundle exec rspec --tag type:system
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ group :test do
gem 'selenium-webdriver'
gem 'cuprite'

# Rack-based AnyCable server implementation
gem 'anycable-rack-server', '0.2.0.rc1'

gem 'test-prof'
end
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ GEM
anycable (1.0.0.rc2)
anyway_config (>= 1.4.2)
grpc (~> 1.17)
anycable-rack-server (0.2.0.rc1)
anycable
anyway_config (>= 1.4.2)
connection_pool (~> 2.2)
websocket (~> 1.2)
anycable-rails (1.0.0.rc4)
anycable (= 1.0.0.rc2)
rails (>= 5)
Expand All @@ -90,6 +95,7 @@ GEM
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.1.6)
connection_pool (2.2.3)
crass (1.0.6)
cuprite (0.10)
capybara (>= 2.1, < 4)
Expand Down Expand Up @@ -267,6 +273,7 @@ GEM
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket (1.2.8)
websocket-driver (0.7.2)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -278,6 +285,7 @@ PLATFORMS
ruby

DEPENDENCIES
anycable-rack-server (= 0.2.0.rc1)
anycable-rails (= 1.0.0.rc4)
bootsnap (>= 1.4.2)
capybara
Expand Down
1 change: 1 addition & 0 deletions config/anycable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ development:

test:
<<: *default
http_broadcast_url: "http://localhost:3023/_anycable_rack_broadcast"

production:
<<: *default
Expand Down
10 changes: 6 additions & 4 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
Rails.application.configure do
# Enforce AnyCable patches to make it possible to use any_cable adapter for system tests
require "anycable/rails/actioncable/connection"
# TEMP: Remove me after final anycable 1.0.0 release
require "anycable/rack/version"

# Specify AnyCable WebSocket server URL to use by JS client
config.after_initialize do
config.action_cable.url = ActionCable.server.config.url = ENV.fetch("CABLE_URL", "ws://127.0.0.1:8080/cable")
end

config.action_cable.url = "/rack_cable"
# Disable built-in Action Cable
config.action_cable.mount_path = nil
# Run AnyCable Rack server at a custom path
config.any_cable_rack.mount_path = "/rack_cable"

# Settings specified here will take precedence over those in config/application.rb.
config.cache_classes = true
Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

require "spec_helper"

# Run embedded RPC server only in RSpec context (it would break when running migrations on CI otherwise)
ENV["ANYCABLE_RUN_RPC"] = "true"

begin
require File.expand_path("../../config/environment", __FILE__)
rescue => e
Expand Down
7 changes: 1 addition & 6 deletions spec/system/support/anycable_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
# Skip assets precompilcation if we exclude system specs.
next if config.filter.opposite.rules[:type] == "system" || config.exclude_pattern.match?(%r{spec/system})

require "anycable/cli"

cli = AnyCable::CLI.new(embedded: true)
cli.run(["--server-command", "anycable-go --broadcast_adapter=http"])

config.after(:suite) do
cli&.shutdown
AnyCable::Rack.rpc_server&.shutdown
end

config.before(:each, type: :system) do
Expand Down
3 changes: 3 additions & 0 deletions spec/system/support/capybara_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# Where to store artifacts (e.g. screenshots, downloaded files, etc.)
Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")

# Use fixed server port to configure AnyCable broadcast url
Capybara.server_port = 3023

Capybara.singleton_class.prepend(Module.new do
attr_accessor :last_used_session

Expand Down

0 comments on commit f711509

Please sign in to comment.