aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/subscription_adapter
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/test/subscription_adapter')
-rw-r--r--actioncable/test/subscription_adapter/async_test.rb6
-rw-r--r--actioncable/test/subscription_adapter/base_test.rb28
-rw-r--r--actioncable/test/subscription_adapter/common.rb66
-rw-r--r--actioncable/test/subscription_adapter/evented_redis_test.rb6
-rw-r--r--actioncable/test/subscription_adapter/inline_test.rb6
-rw-r--r--actioncable/test/subscription_adapter/postgresql_test.rb18
-rw-r--r--actioncable/test/subscription_adapter/redis_test.rb8
-rw-r--r--actioncable/test/subscription_adapter/subscriber_map_test.rb4
8 files changed, 70 insertions, 72 deletions
diff --git a/actioncable/test/subscription_adapter/async_test.rb b/actioncable/test/subscription_adapter/async_test.rb
index 8f413f14c2..7bc2e55d40 100644
--- a/actioncable/test/subscription_adapter/async_test.rb
+++ b/actioncable/test/subscription_adapter/async_test.rb
@@ -1,5 +1,5 @@
-require 'test_helper'
-require_relative './common'
+require "test_helper"
+require_relative "./common"
class AsyncAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
@@ -12,6 +12,6 @@ class AsyncAdapterTest < ActionCable::TestCase
end
def cable_config
- { adapter: 'async' }
+ { adapter: "async" }
end
end
diff --git a/actioncable/test/subscription_adapter/base_test.rb b/actioncable/test/subscription_adapter/base_test.rb
index 256dce673f..212ea49d2f 100644
--- a/actioncable/test/subscription_adapter/base_test.rb
+++ b/actioncable/test/subscription_adapter/base_test.rb
@@ -1,5 +1,5 @@
-require 'test_helper'
-require 'stubs/test_server'
+require "test_helper"
+require "stubs/test_server"
class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
## TEST THAT ERRORS ARE RETURNED FOR INHERITORS THAT DON'T OVERRIDE METHODS
@@ -15,31 +15,31 @@ class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
test "#broadcast returns NotImplementedError by default" do
assert_raises NotImplementedError do
- BrokenAdapter.new(@server).broadcast('channel', 'payload')
+ BrokenAdapter.new(@server).broadcast("channel", "payload")
end
end
test "#subscribe returns NotImplementedError by default" do
- callback = lambda { puts 'callback' }
- success_callback = lambda { puts 'success' }
+ callback = lambda { puts "callback" }
+ success_callback = lambda { puts "success" }
assert_raises NotImplementedError do
- BrokenAdapter.new(@server).subscribe('channel', callback, success_callback)
+ BrokenAdapter.new(@server).subscribe("channel", callback, success_callback)
end
end
test "#unsubscribe returns NotImplementedError by default" do
- callback = lambda { puts 'callback' }
+ callback = lambda { puts "callback" }
assert_raises NotImplementedError do
- BrokenAdapter.new(@server).unsubscribe('channel', callback)
+ BrokenAdapter.new(@server).unsubscribe("channel", callback)
end
end
# TEST METHODS THAT ARE REQUIRED OF THE ADAPTER'S BACKEND STORAGE OBJECT
test "#broadcast is implemented" do
- broadcast = SuccessAdapter.new(@server).broadcast('channel', 'payload')
+ broadcast = SuccessAdapter.new(@server).broadcast("channel", "payload")
assert_respond_to(SuccessAdapter.new(@server), :broadcast)
@@ -49,9 +49,9 @@ class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
end
test "#subscribe is implemented" do
- callback = lambda { puts 'callback' }
- success_callback = lambda { puts 'success' }
- subscribe = SuccessAdapter.new(@server).subscribe('channel', callback, success_callback)
+ callback = lambda { puts "callback" }
+ success_callback = lambda { puts "success" }
+ subscribe = SuccessAdapter.new(@server).subscribe("channel", callback, success_callback)
assert_respond_to(SuccessAdapter.new(@server), :subscribe)
@@ -61,8 +61,8 @@ class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
end
test "#unsubscribe is implemented" do
- callback = lambda { puts 'callback' }
- unsubscribe = SuccessAdapter.new(@server).unsubscribe('channel', callback)
+ callback = lambda { puts "callback" }
+ unsubscribe = SuccessAdapter.new(@server).unsubscribe("channel", callback)
assert_respond_to(SuccessAdapter.new(@server), :unsubscribe)
diff --git a/actioncable/test/subscription_adapter/common.rb b/actioncable/test/subscription_adapter/common.rb
index 285c690df0..1538157995 100644
--- a/actioncable/test/subscription_adapter/common.rb
+++ b/actioncable/test/subscription_adapter/common.rb
@@ -1,8 +1,8 @@
-require 'test_helper'
-require 'concurrent'
+require "test_helper"
+require "concurrent"
-require 'active_support/core_ext/hash/indifferent_access'
-require 'pathname'
+require "active_support/core_ext/hash/indifferent_access"
+require "pathname"
module CommonSubscriptionAdapterTest
WAIT_WHEN_EXPECTING_EVENT = 3
@@ -11,7 +11,7 @@ module CommonSubscriptionAdapterTest
def setup
server = ActionCable::Server::Base.new
server.config.cable = cable_config.with_indifferent_access
- server.config.use_faye = ENV['FAYE'].present?
+ server.config.use_faye = ENV["FAYE"].present?
adapter_klass = server.config.pubsub_adapter
@@ -23,7 +23,6 @@ module CommonSubscriptionAdapterTest
[@rx_adapter, @tx_adapter].uniq.each(&:shutdown)
end
-
def subscribe_as_queue(channel, adapter = @rx_adapter)
queue = Queue.new
@@ -41,77 +40,76 @@ module CommonSubscriptionAdapterTest
adapter.unsubscribe(channel, callback) if subscribed.set?
end
-
def test_subscribe_and_unsubscribe
- subscribe_as_queue('channel') do |queue|
+ subscribe_as_queue("channel") do |queue|
end
end
def test_basic_broadcast
- subscribe_as_queue('channel') do |queue|
- @tx_adapter.broadcast('channel', 'hello world')
+ subscribe_as_queue("channel") do |queue|
+ @tx_adapter.broadcast("channel", "hello world")
- assert_equal 'hello world', queue.pop
+ assert_equal "hello world", queue.pop
end
end
def test_broadcast_after_unsubscribe
keep_queue = nil
- subscribe_as_queue('channel') do |queue|
+ subscribe_as_queue("channel") do |queue|
keep_queue = queue
- @tx_adapter.broadcast('channel', 'hello world')
+ @tx_adapter.broadcast("channel", "hello world")
- assert_equal 'hello world', queue.pop
+ assert_equal "hello world", queue.pop
end
- @tx_adapter.broadcast('channel', 'hello void')
+ @tx_adapter.broadcast("channel", "hello void")
sleep WAIT_WHEN_NOT_EXPECTING_EVENT
assert_empty keep_queue
end
def test_multiple_broadcast
- subscribe_as_queue('channel') do |queue|
- @tx_adapter.broadcast('channel', 'bananas')
- @tx_adapter.broadcast('channel', 'apples')
+ subscribe_as_queue("channel") do |queue|
+ @tx_adapter.broadcast("channel", "bananas")
+ @tx_adapter.broadcast("channel", "apples")
received = []
2.times { received << queue.pop }
- assert_equal ['apples', 'bananas'], received.sort
+ assert_equal ["apples", "bananas"], received.sort
end
end
def test_identical_subscriptions
- subscribe_as_queue('channel') do |queue|
- subscribe_as_queue('channel') do |queue_2|
- @tx_adapter.broadcast('channel', 'hello')
+ subscribe_as_queue("channel") do |queue|
+ subscribe_as_queue("channel") do |queue_2|
+ @tx_adapter.broadcast("channel", "hello")
- assert_equal 'hello', queue_2.pop
+ assert_equal "hello", queue_2.pop
end
- assert_equal 'hello', queue.pop
+ assert_equal "hello", queue.pop
end
end
def test_simultaneous_subscriptions
- subscribe_as_queue('channel') do |queue|
- subscribe_as_queue('other channel') do |queue_2|
- @tx_adapter.broadcast('channel', 'apples')
- @tx_adapter.broadcast('other channel', 'oranges')
+ subscribe_as_queue("channel") do |queue|
+ subscribe_as_queue("other channel") do |queue_2|
+ @tx_adapter.broadcast("channel", "apples")
+ @tx_adapter.broadcast("other channel", "oranges")
- assert_equal 'apples', queue.pop
- assert_equal 'oranges', queue_2.pop
+ assert_equal "apples", queue.pop
+ assert_equal "oranges", queue_2.pop
end
end
end
def test_channel_filtered_broadcast
- subscribe_as_queue('channel') do |queue|
- @tx_adapter.broadcast('other channel', 'one')
- @tx_adapter.broadcast('channel', 'two')
+ subscribe_as_queue("channel") do |queue|
+ @tx_adapter.broadcast("other channel", "one")
+ @tx_adapter.broadcast("channel", "two")
- assert_equal 'two', queue.pop
+ assert_equal "two", queue.pop
end
end
end
diff --git a/actioncable/test/subscription_adapter/evented_redis_test.rb b/actioncable/test/subscription_adapter/evented_redis_test.rb
index 6d20e6ed78..d6ca0e77cb 100644
--- a/actioncable/test/subscription_adapter/evented_redis_test.rb
+++ b/actioncable/test/subscription_adapter/evented_redis_test.rb
@@ -1,5 +1,5 @@
-require 'test_helper'
-require_relative './common'
+require "test_helper"
+require_relative "./common"
class EventedRedisAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
@@ -16,6 +16,6 @@ class EventedRedisAdapterTest < ActionCable::TestCase
end
def cable_config
- { adapter: 'evented_redis', url: 'redis://127.0.0.1:6379/12' }
+ { adapter: "evented_redis", url: "redis://127.0.0.1:6379/12" }
end
end
diff --git a/actioncable/test/subscription_adapter/inline_test.rb b/actioncable/test/subscription_adapter/inline_test.rb
index 75ea51e6b3..52bfa00aba 100644
--- a/actioncable/test/subscription_adapter/inline_test.rb
+++ b/actioncable/test/subscription_adapter/inline_test.rb
@@ -1,5 +1,5 @@
-require 'test_helper'
-require_relative './common'
+require "test_helper"
+require_relative "./common"
class InlineAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
@@ -12,6 +12,6 @@ class InlineAdapterTest < ActionCable::TestCase
end
def cable_config
- { adapter: 'inline' }
+ { adapter: "inline" }
end
end
diff --git a/actioncable/test/subscription_adapter/postgresql_test.rb b/actioncable/test/subscription_adapter/postgresql_test.rb
index 214352a0b2..beb6efab28 100644
--- a/actioncable/test/subscription_adapter/postgresql_test.rb
+++ b/actioncable/test/subscription_adapter/postgresql_test.rb
@@ -1,18 +1,18 @@
-require 'test_helper'
-require_relative './common'
+require "test_helper"
+require_relative "./common"
-require 'active_record'
+require "active_record"
class PostgresqlAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
def setup
- database_config = { 'adapter' => 'postgresql', 'database' => 'activerecord_unittest' }
- ar_tests = File.expand_path('../../../activerecord/test', __dir__)
+ database_config = { "adapter" => "postgresql", "database" => "activerecord_unittest" }
+ ar_tests = File.expand_path("../../../activerecord/test", __dir__)
if Dir.exist?(ar_tests)
- require File.join(ar_tests, 'config')
- require File.join(ar_tests, 'support/config')
- local_config = ARTest.config['arunit']
+ require File.join(ar_tests, "config")
+ require File.join(ar_tests, "support/config")
+ local_config = ARTest.config["arunit"]
database_config.update local_config if local_config
end
@@ -35,6 +35,6 @@ class PostgresqlAdapterTest < ActionCable::TestCase
end
def cable_config
- { adapter: 'postgresql' }
+ { adapter: "postgresql" }
end
end
diff --git a/actioncable/test/subscription_adapter/redis_test.rb b/actioncable/test/subscription_adapter/redis_test.rb
index 4f34dd86c9..2ba5636656 100644
--- a/actioncable/test/subscription_adapter/redis_test.rb
+++ b/actioncable/test/subscription_adapter/redis_test.rb
@@ -1,16 +1,16 @@
-require 'test_helper'
-require_relative './common'
+require "test_helper"
+require_relative "./common"
class RedisAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
def cable_config
- { adapter: 'redis', driver: 'ruby', url: 'redis://127.0.0.1:6379/12' }
+ { adapter: "redis", driver: "ruby", url: "redis://127.0.0.1:6379/12" }
end
end
class RedisAdapterTest::Hiredis < RedisAdapterTest
def cable_config
- super.merge(driver: 'hiredis')
+ super.merge(driver: "hiredis")
end
end
diff --git a/actioncable/test/subscription_adapter/subscriber_map_test.rb b/actioncable/test/subscription_adapter/subscriber_map_test.rb
index 5965ac2b90..76b984c849 100644
--- a/actioncable/test/subscription_adapter/subscriber_map_test.rb
+++ b/actioncable/test/subscription_adapter/subscriber_map_test.rb
@@ -1,11 +1,11 @@
-require 'test_helper'
+require "test_helper"
class SubscriberMapTest < ActionCable::TestCase
test "broadcast should not change subscribers" do
setup_subscription_map
origin = @subscription_map.instance_variable_get(:@subscribers).dup
- @subscription_map.broadcast('not_exist_channel', '')
+ @subscription_map.broadcast("not_exist_channel", "")
assert_equal origin, @subscription_map.instance_variable_get(:@subscribers)
end