mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
396bf6cd7a
connection so it doesn't pollute the rest of the test suite.
81 lines
2.1 KiB
Ruby
81 lines
2.1 KiB
Ruby
require 'helper'
|
|
require 'sidekiq/redis_connection'
|
|
|
|
class TestRedisConnection < MiniTest::Unit::TestCase
|
|
|
|
describe ".create" do
|
|
|
|
it "creates a pooled redis connection" do
|
|
pool = Sidekiq::RedisConnection.create
|
|
assert_equal Redis, pool.checkout.class
|
|
end
|
|
|
|
describe "namespace" do
|
|
before do
|
|
Sidekiq.options[:namespace] = "xxx"
|
|
end
|
|
|
|
after do
|
|
Sidekiq.options[:namespace] = nil
|
|
end
|
|
|
|
it "uses a given :namespace" do
|
|
pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
|
|
assert_equal "xxx", pool.checkout.namespace
|
|
end
|
|
|
|
it "uses :namespace from Sidekiq.options" do
|
|
pool = Sidekiq::RedisConnection.create
|
|
assert_equal "xxx", pool.checkout.namespace
|
|
end
|
|
|
|
it "uses given :namespace over :namespace from Sidekiq.options" do
|
|
Sidekiq.options[:namespace] = "xxx"
|
|
pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
|
|
assert_equal "yyy", pool.checkout.namespace
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
describe ".determine_redis_provider" do
|
|
|
|
def with_env_var(var, uri, skip_provider=false)
|
|
vars = ['REDISTOGO_URL', 'REDIS_PROVIDER', 'REDIS_URL'] - [var]
|
|
vars.each do |v|
|
|
next if skip_provider
|
|
ENV[v] = nil
|
|
end
|
|
ENV[var] = uri
|
|
assert_equal uri, Sidekiq::RedisConnection.determine_redis_provider
|
|
ENV[var] = nil
|
|
end
|
|
|
|
describe "with REDISTOGO_URL set" do
|
|
it "sets connection URI to RedisToGo" do
|
|
with_env_var 'REDISTOGO_URL', 'redis://redis-to-go:6379/0'
|
|
end
|
|
end
|
|
|
|
describe "with REDIS_PROVIDER set" do
|
|
it "sets connection URI to the provider" do
|
|
uri = 'redis://sidekiq-redis-provider:6379/0'
|
|
provider = 'SIDEKIQ_REDIS_PROVIDER'
|
|
|
|
ENV['REDIS_PROVIDER'] = provider
|
|
ENV[provider] = uri
|
|
|
|
with_env_var provider, uri, true
|
|
|
|
ENV[provider] = nil
|
|
end
|
|
end
|
|
|
|
describe "with REDIS_URL set" do
|
|
it "sets connection URI to custom uri" do
|
|
with_env_var 'REDIS_URL', 'redis://redis-uri:6379/0'
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|