summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Mazetto <gabriel@gitlab.com>2016-08-06 03:01:52 +0200
committerGabriel Mazetto <gabriel@gitlab.com>2016-08-06 04:15:16 +0200
commited0a7c254ab32130296fb7ee467f655d200d7854 (patch)
tree42714bb5b3fafea87d3b889da94474b788897f26
parentce41b5c73f7574ec19c47f24e9450ff1b54ef1b1 (diff)
downloadgitlab-ce-ed0a7c254ab32130296fb7ee467f655d200d7854.tar.gz
Small refactor in Redis class and improved specs
-rw-r--r--lib/gitlab/redis.rb6
-rw-r--r--spec/fixtures/config/redis_new_format_host.yml6
-rw-r--r--spec/fixtures/config/redis_old_format_socket.yml6
-rw-r--r--spec/lib/gitlab/redis_spec.rb7
4 files changed, 16 insertions, 9 deletions
diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb
index 72fa80e61e2..9376b54f43b 100644
--- a/lib/gitlab/redis.rb
+++ b/lib/gitlab/redis.rb
@@ -19,7 +19,7 @@ module Gitlab
class << self
def params
- PARAMS_MUTEX.synchronize { new.params }
+ @params || PARAMS_MUTEX.synchronize { @params = new.params }
end
# @deprecated Use .params instead to get sentinel support
@@ -35,6 +35,10 @@ module Gitlab
end
@pool.with { |redis| yield redis }
end
+
+ def reset_params!
+ @params = nil
+ end
end
def initialize(rails_env = nil)
diff --git a/spec/fixtures/config/redis_new_format_host.yml b/spec/fixtures/config/redis_new_format_host.yml
index 5e5bf6e0ccd..13772677a45 100644
--- a/spec/fixtures/config/redis_new_format_host.yml
+++ b/spec/fixtures/config/redis_new_format_host.yml
@@ -1,7 +1,7 @@
# redis://[:password@]host[:port][/db-number][?option=value]
# more details: http://www.iana.org/assignments/uri-schemes/prov/redis
development:
- url: redis://:mypassword@localhost:6379/99
+ url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: localhost
@@ -10,7 +10,7 @@ development:
host: slave2
port: 26381 # point to sentinel, not to redis port
test:
- url: redis://:mypassword@localhost:6379/99
+ url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: localhost
@@ -19,7 +19,7 @@ test:
host: slave2
port: 26381 # point to sentinel, not to redis port
production:
- url: redis://:mypassword@localhost:6379/99
+ url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: slave1
diff --git a/spec/fixtures/config/redis_old_format_socket.yml b/spec/fixtures/config/redis_old_format_socket.yml
index cb39b6fb9e2..fd31ce8ea3d 100644
--- a/spec/fixtures/config/redis_old_format_socket.yml
+++ b/spec/fixtures/config/redis_old_format_socket.yml
@@ -1,3 +1,3 @@
-development: unix:/path/to/redis.sock
-test: unix:/path/to/redis.sock
-production: unix:/path/to/redis.sock
+development: unix:/path/to/old/redis.sock
+test: unix:/path/to/old/redis.sock
+production: unix:/path/to/old/redis.sock
diff --git a/spec/lib/gitlab/redis_spec.rb b/spec/lib/gitlab/redis_spec.rb
index 04257f89627..879ed30841c 100644
--- a/spec/lib/gitlab/redis_spec.rb
+++ b/spec/lib/gitlab/redis_spec.rb
@@ -3,6 +3,9 @@ require 'spec_helper'
describe Gitlab::Redis do
let(:redis_config) { Rails.root.join('config', 'resque.yml').to_s }
+ before(:each) { described_class.reset_params! }
+ after(:each) { described_class.reset_params! }
+
describe '.params' do
subject { described_class.params }
@@ -14,7 +17,7 @@ describe Gitlab::Redis do
it 'returns path key instead' do
expect_any_instance_of(described_class).to receive(:config_file) { config_old }
- is_expected.to include(path: '/path/to/redis.sock')
+ is_expected.to include(path: '/path/to/old/redis.sock')
is_expected.not_to have_key(:url)
end
end
@@ -46,7 +49,7 @@ describe Gitlab::Redis do
it 'returns hash with host, port, db, and password' do
expect_any_instance_of(described_class).to receive(:config_file) { config_new }
- is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99)
+ is_expected.to include(host: 'localhost', password: 'mynewpassword', port: 6379, db: 99)
is_expected.not_to have_key(:url)
end
end