Commit ed0a7c25 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Small refactor in Redis class and improved specs

parent ce41b5c7
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
class << self class << self
def params def params
PARAMS_MUTEX.synchronize { new.params } @params || PARAMS_MUTEX.synchronize { @params = new.params }
end end
# @deprecated Use .params instead to get sentinel support # @deprecated Use .params instead to get sentinel support
...@@ -35,6 +35,10 @@ module Gitlab ...@@ -35,6 +35,10 @@ module Gitlab
end end
@pool.with { |redis| yield redis } @pool.with { |redis| yield redis }
end end
def reset_params!
@params = nil
end
end end
def initialize(rails_env = nil) def initialize(rails_env = nil)
......
# redis://[:password@]host[:port][/db-number][?option=value] # redis://[:password@]host[:port][/db-number][?option=value]
# more details: http://www.iana.org/assignments/uri-schemes/prov/redis # more details: http://www.iana.org/assignments/uri-schemes/prov/redis
development: development:
url: redis://:mypassword@localhost:6379/99 url: redis://:mynewpassword@localhost:6379/99
sentinels: sentinels:
- -
host: localhost host: localhost
...@@ -10,7 +10,7 @@ development: ...@@ -10,7 +10,7 @@ development:
host: slave2 host: slave2
port: 26381 # point to sentinel, not to redis port port: 26381 # point to sentinel, not to redis port
test: test:
url: redis://:mypassword@localhost:6379/99 url: redis://:mynewpassword@localhost:6379/99
sentinels: sentinels:
- -
host: localhost host: localhost
...@@ -19,7 +19,7 @@ test: ...@@ -19,7 +19,7 @@ test:
host: slave2 host: slave2
port: 26381 # point to sentinel, not to redis port port: 26381 # point to sentinel, not to redis port
production: production:
url: redis://:mypassword@localhost:6379/99 url: redis://:mynewpassword@localhost:6379/99
sentinels: sentinels:
- -
host: slave1 host: slave1
......
development: unix:/path/to/redis.sock development: unix:/path/to/old/redis.sock
test: unix:/path/to/redis.sock test: unix:/path/to/old/redis.sock
production: unix:/path/to/redis.sock production: unix:/path/to/old/redis.sock
...@@ -3,6 +3,9 @@ require 'spec_helper' ...@@ -3,6 +3,9 @@ require 'spec_helper'
describe Gitlab::Redis do describe Gitlab::Redis do
let(:redis_config) { Rails.root.join('config', 'resque.yml').to_s } 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 describe '.params' do
subject { described_class.params } subject { described_class.params }
...@@ -14,7 +17,7 @@ describe Gitlab::Redis do ...@@ -14,7 +17,7 @@ describe Gitlab::Redis do
it 'returns path key instead' do it 'returns path key instead' do
expect_any_instance_of(described_class).to receive(:config_file) { config_old } 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) is_expected.not_to have_key(:url)
end end
end end
...@@ -46,7 +49,7 @@ describe Gitlab::Redis do ...@@ -46,7 +49,7 @@ describe Gitlab::Redis do
it 'returns hash with host, port, db, and password' do it 'returns hash with host, port, db, and password' do
expect_any_instance_of(described_class).to receive(:config_file) { config_new } 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) is_expected.not_to have_key(:url)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment