diff --git a/.github/workflows/system_test.yml b/.github/workflows/system_test.yml index 36b591d..58ecacd 100644 --- a/.github/workflows/system_test.yml +++ b/.github/workflows/system_test.yml @@ -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 diff --git a/Gemfile b/Gemfile index 5143832..ff07164 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 00561d5..8a23489 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/config/anycable.yml b/config/anycable.yml index a8a5521..7133695 100644 --- a/config/anycable.yml +++ b/config/anycable.yml @@ -31,6 +31,7 @@ development: test: <<: *default + http_broadcast_url: "http://localhost:3023/_anycable_rack_broadcast" production: <<: *default diff --git a/config/environments/test.rb b/config/environments/test.rb index ca253ab..872d413 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1a61495..76bc36f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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 diff --git a/spec/system/support/anycable_setup.rb b/spec/system/support/anycable_setup.rb index 3371fcd..1c446b6 100644 --- a/spec/system/support/anycable_setup.rb +++ b/spec/system/support/anycable_setup.rb @@ -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 diff --git a/spec/system/support/capybara_setup.rb b/spec/system/support/capybara_setup.rb index da350c3..6ec7529 100644 --- a/spec/system/support/capybara_setup.rb +++ b/spec/system/support/capybara_setup.rb @@ -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