From ea48409e88c9269887b41da3d62cf24bfa6dcad3 Mon Sep 17 00:00:00 2001 From: Andrew Babichev Date: Thu, 6 Dec 2018 17:15:47 +0200 Subject: [PATCH] Set REDIS_URL to use non-default host in test env --- test/helper.rb | 2 ++ test/test_redis_connection.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index c1e94dccd..da80a46a9 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -20,6 +20,8 @@ end end +ENV['REDIS_URL'] ||= 'redis://localhost/15' + Sidekiq.logger.level = Logger::ERROR def capture_logging(lvl=Logger::INFO) diff --git a/test/test_redis_connection.rb b/test/test_redis_connection.rb index 6c0879bfe..2af17676b 100644 --- a/test/test_redis_connection.rb +++ b/test/test_redis_connection.rb @@ -7,6 +7,12 @@ class TestRedisConnection < Minitest::Test describe ".create" do before do Sidekiq.options = Sidekiq::DEFAULTS.dup + @old = ENV['REDIS_URL'] + ENV['REDIS_URL'] = 'redis://localhost/15' + end + + after do + ENV['REDIS_URL'] = @old end # To support both redis-rb 3.3.x #client and 4.0.x #_client @@ -82,7 +88,7 @@ def server_connection(*args) it "disables client setname with nil id" do pool = Sidekiq::RedisConnection.create(:id => nil) assert_equal Redis, pool.checkout.class - assert_equal "redis://127.0.0.1:6379/0", pool.checkout.connection.fetch(:id) + assert_equal "redis://localhost:6379/15", pool.checkout.connection.fetch(:id) end describe "network_timeout" do @@ -124,7 +130,7 @@ def server_connection(*args) pool = Sidekiq::RedisConnection.create(:path => "/var/run/redis.sock") assert_equal "unix", client_for(pool.checkout).scheme assert_equal "/var/run/redis.sock", pool.checkout.connection.fetch(:location) - assert_equal 0, pool.checkout.connection.fetch(:db) + assert_equal 15, pool.checkout.connection.fetch(:db) end it "uses a given :path and :db" do