2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
2017-06-11 08:59:23 -04:00
|
|
|
require_relative "common"
|
|
|
|
require_relative "channel_prefix"
|
2016-01-24 05:43:40 -05:00
|
|
|
|
2017-11-13 02:55:06 -05:00
|
|
|
require "action_cable/subscription_adapter/redis"
|
|
|
|
|
2016-01-24 05:43:40 -05:00
|
|
|
class RedisAdapterTest < ActionCable::TestCase
|
|
|
|
include CommonSubscriptionAdapterTest
|
2017-01-17 23:20:36 -05:00
|
|
|
include ChannelPrefixTest
|
2016-01-24 05:43:40 -05:00
|
|
|
|
|
|
|
def cable_config
|
2019-02-05 09:50:06 -05:00
|
|
|
{ adapter: "redis", driver: "ruby" }.tap do |x|
|
|
|
|
if host = URI(ENV["REDIS_URL"] || "").hostname
|
|
|
|
x[:host] = host
|
|
|
|
end
|
|
|
|
end
|
2016-01-31 10:00:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RedisAdapterTest::Hiredis < RedisAdapterTest
|
|
|
|
def cable_config
|
2016-08-06 13:15:15 -04:00
|
|
|
super.merge(driver: "hiredis")
|
2016-01-24 05:43:40 -05:00
|
|
|
end
|
|
|
|
end
|
2017-06-21 21:10:08 -04:00
|
|
|
|
|
|
|
class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
|
|
|
def cable_config
|
|
|
|
alt_cable_config = super.dup
|
|
|
|
alt_cable_config.delete(:url)
|
2019-02-05 09:50:06 -05:00
|
|
|
alt_cable_config.merge(host: URI(ENV["REDIS_URL"] || "").hostname || "127.0.0.1", port: 6379, db: 12)
|
2017-11-13 02:55:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-13 12:27:23 -05:00
|
|
|
class RedisAdapterTest::ConnectorDefaultID < ActionCable::TestCase
|
|
|
|
def setup
|
|
|
|
server = ActionCable::Server::Base.new
|
|
|
|
server.config.cable = cable_config.merge(adapter: "redis").with_indifferent_access
|
|
|
|
server.config.logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
|
2017-11-13 02:55:06 -05:00
|
|
|
|
2019-02-13 12:27:23 -05:00
|
|
|
@adapter = server.config.pubsub_adapter.new(server)
|
2017-11-13 02:55:06 -05:00
|
|
|
end
|
|
|
|
|
2019-02-13 12:27:23 -05:00
|
|
|
def cable_config
|
|
|
|
{ url: 1, host: 2, port: 3, db: 4, password: 5 }
|
|
|
|
end
|
|
|
|
|
|
|
|
def connection_id
|
|
|
|
"ActionCable-PID-#{$$}"
|
|
|
|
end
|
2018-09-05 09:54:44 -04:00
|
|
|
|
2019-02-13 12:27:23 -05:00
|
|
|
def expected_connection
|
|
|
|
cable_config.merge(id: connection_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sets connection id for connection" do
|
|
|
|
assert_called_with ::Redis, :new, [ expected_connection.stringify_keys ] do
|
|
|
|
@adapter.send(:redis_connection)
|
2018-09-05 09:54:44 -04:00
|
|
|
end
|
|
|
|
end
|
2019-02-13 12:27:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class RedisAdapterTest::ConnectorCustomID < RedisAdapterTest::ConnectorDefaultID
|
|
|
|
def cable_config
|
|
|
|
super.merge(id: connection_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def connection_id
|
|
|
|
"Some custom ID"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RedisAdapterTest::ConnectorWithExcluded < RedisAdapterTest::ConnectorDefaultID
|
|
|
|
def cable_config
|
|
|
|
super.merge(adapter: "redis", channel_prefix: "custom")
|
|
|
|
end
|
2018-09-05 09:54:44 -04:00
|
|
|
|
2019-02-13 12:27:23 -05:00
|
|
|
def expected_connection
|
|
|
|
super.except(:adapter, :channel_prefix)
|
2017-06-21 21:10:08 -04:00
|
|
|
end
|
|
|
|
end
|