Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6f318795
Commit
6f318795
authored
Jul 08, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed specs for Gitlab::Redis and code for Redis Sentinel support
parent
eacdb101
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
30 deletions
+27
-30
config/mail_room.yml
config/mail_room.yml
+1
-1
lib/gitlab/mail_room.rb
lib/gitlab/mail_room.rb
+5
-5
lib/gitlab/redis.rb
lib/gitlab/redis.rb
+5
-4
spec/lib/gitlab/redis_spec.rb
spec/lib/gitlab/redis_spec.rb
+16
-20
No files found.
config/mail_room.yml
View file @
6f318795
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require_relative "lib/gitlab/mail_room" unless defined?(Gitlab::MailRoom)
require_relative "lib/gitlab/mail_room" unless defined?(Gitlab::MailRoom)
config = Gitlab::MailRoom.config
config = Gitlab::MailRoom.config
if Gitlab::Mail
r
oom.enabled?
if Gitlab::Mail
R
oom.enabled?
%>
%>
-
-
:host: <%= config[:host].to_json %>
:host: <%= config[:host].to_json %>
...
...
lib/gitlab/mail_room.rb
View file @
6f318795
require
'yaml'
require
'yaml'
require
'json'
require
'json'
require_relative
'
lib/gitlab/
redis'
unless
defined?
(
Gitlab
::
Redis
)
require_relative
'redis'
unless
defined?
(
Gitlab
::
Redis
)
module
Gitlab
module
Gitlab
module
MailRoom
module
MailRoom
class
<<
self
class
<<
self
def
enabled?
def
enabled?
config
[
:enabled
]
&&
config
[
:address
]
config
[
:enabled
]
&&
config
[
:address
]
end
end
...
@@ -18,7 +17,7 @@ module Gitlab
...
@@ -18,7 +17,7 @@ module Gitlab
private
private
def
fetch_config
def
fetch_config
return
nil
unless
File
.
exists
?
(
config_file
)
return
{}
unless
File
.
exist
?
(
config_file
)
rails_env
=
ENV
[
'RAILS_ENV'
]
||
ENV
[
'RACK_ENV'
]
||
'development'
rails_env
=
ENV
[
'RAILS_ENV'
]
||
ENV
[
'RACK_ENV'
]
||
'development'
all_config
=
YAML
.
load_file
(
config_file
)[
rails_env
].
deep_symbolize_keys
all_config
=
YAML
.
load_file
(
config_file
)[
rails_env
].
deep_symbolize_keys
...
@@ -33,11 +32,12 @@ module Gitlab
...
@@ -33,11 +32,12 @@ module Gitlab
if
config
[
:enabled
]
&&
config
[
:address
]
if
config
[
:enabled
]
&&
config
[
:address
]
config
[
:redis_url
]
=
Gitlab
::
Redis
.
new
(
rails_env
).
url
config
[
:redis_url
]
=
Gitlab
::
Redis
.
new
(
rails_env
).
url
end
end
config
end
end
def
config_file
def
config_file
file
=
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
||
'config/gitlab.yml'
ENV
[
'MAIL_ROOM_GITLAB_CONFIG_FILE'
]
||
File
.
expand_path
(
'../../../config/gitlab.yml'
,
__FILE__
)
File
.
expand_path
(
"../../../
#{
file
}
"
,
__FILE__
)
end
end
end
end
end
end
...
...
lib/gitlab/redis.rb
View file @
6f318795
...
@@ -19,7 +19,7 @@ module Gitlab
...
@@ -19,7 +19,7 @@ module Gitlab
class
<<
self
class
<<
self
def
params
def
params
@params
||
PARAMS_MUTEX
.
synchronize
{
@params
=
new
.
params
}
PARAMS_MUTEX
.
synchronize
{
new
.
params
}
end
end
# @deprecated Use .params instead to get sentinel support
# @deprecated Use .params instead to get sentinel support
...
@@ -38,7 +38,7 @@ module Gitlab
...
@@ -38,7 +38,7 @@ module Gitlab
end
end
def
initialize
(
rails_env
=
nil
)
def
initialize
(
rails_env
=
nil
)
@rails_env
=
rails_env
||
Rails
.
env
@rails_env
=
rails_env
||
::
Rails
.
env
end
end
def
params
def
params
...
@@ -55,7 +55,7 @@ module Gitlab
...
@@ -55,7 +55,7 @@ module Gitlab
# Redis::Store does not handle Unix sockets well, so let's do it for them
# Redis::Store does not handle Unix sockets well, so let's do it for them
config
[
:path
]
=
redis_uri
.
path
config
[
:path
]
=
redis_uri
.
path
else
else
redis_hash
=
::
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
redis_uri
)
redis_hash
=
::
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
config
[
:url
]
)
config
.
merge!
(
redis_hash
)
config
.
merge!
(
redis_hash
)
end
end
...
@@ -74,7 +74,8 @@ module Gitlab
...
@@ -74,7 +74,8 @@ module Gitlab
end
end
def
fetch_config
def
fetch_config
File
.
exists?
(
config_file
)
?
YAML
.
load_file
(
config_file
)[
@rails_env
]
:
false
file
=
config_file
File
.
exist?
(
file
)
?
YAML
.
load_file
(
file
)[
@rails_env
]
:
false
end
end
def
config_file
def
config_file
...
...
spec/lib/gitlab/redis_
config_
spec.rb
→
spec/lib/gitlab/redis_spec.rb
View file @
6f318795
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Redis
Config
do
describe
Gitlab
::
Redis
do
let
(
:redis_config
)
{
Rails
.
root
.
join
(
'config'
,
'resque.yml'
)
}
let
(
:redis_config
)
{
Rails
.
root
.
join
(
'config'
,
'resque.yml'
)
.
to_s
}
describe
'.params'
do
describe
'.params'
do
subject
{
described_class
.
params
}
subject
{
described_class
.
params
}
context
'when url contains unix socket reference'
do
context
'when url contains unix socket reference'
do
let
(
:config_old
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_old_format_socket.yml'
)
}
let
(
:config_old
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_old_format_socket.yml'
)
.
to_s
}
let
(
:config_new
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_new_format_socket.yml'
)
}
let
(
:config_new
)
{
Rails
.
root
.
join
(
'spec/fixtures/config/redis_new_format_socket.yml'
)
.
to_s
}
context
'with old format'
do
context
'with old format'
do
it
'returns path key instead'
do
it
'returns path key instead'
do
allow
(
Gitlab
::
RedisConfig
).
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/redis.sock'
)
is_expected
.
not_to
have_key
(
:url
)
is_expected
.
not_to
have_key
(
:url
)
...
@@ -21,7 +21,7 @@ describe Gitlab::RedisConfig do
...
@@ -21,7 +21,7 @@ describe Gitlab::RedisConfig do
context
'with new format'
do
context
'with new format'
do
it
'returns path key instead'
do
it
'returns path key instead'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_new
}
expect_any_instance_of
(
described_class
).
to
receive
(
:config_file
)
{
config_new
}
is_expected
.
to
include
(
path:
'/path/to/redis.sock'
)
is_expected
.
to
include
(
path:
'/path/to/redis.sock'
)
is_expected
.
not_to
have_key
(
:url
)
is_expected
.
not_to
have_key
(
:url
)
...
@@ -35,7 +35,7 @@ describe Gitlab::RedisConfig do
...
@@ -35,7 +35,7 @@ describe Gitlab::RedisConfig do
context
'with old format'
do
context
'with old format'
do
it
'returns hash with host, port, db, and password'
do
it
'returns hash with host, port, db, and password'
do
allow
(
Gitlab
::
RedisConfig
).
to
receive
(
:config_file
)
{
config_old
}
expect_any_instance_of
(
described_class
).
to
receive
(
:config_file
)
{
config_old
}
is_expected
.
to
include
(
host:
'localhost'
,
password:
'mypassword'
,
port:
6379
,
db:
99
)
is_expected
.
to
include
(
host:
'localhost'
,
password:
'mypassword'
,
port:
6379
,
db:
99
)
is_expected
.
not_to
have_key
(
:url
)
is_expected
.
not_to
have_key
(
:url
)
...
@@ -44,7 +44,7 @@ describe Gitlab::RedisConfig do
...
@@ -44,7 +44,7 @@ describe Gitlab::RedisConfig do
context
'with new format'
do
context
'with new format'
do
it
'returns hash with host, port, db, and password'
do
it
'returns hash with host, port, db, and password'
do
allow
(
Gitlab
::
RedisConfig
).
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:
'mypassword'
,
port:
6379
,
db:
99
)
is_expected
.
not_to
have_key
(
:url
)
is_expected
.
not_to
have_key
(
:url
)
...
@@ -53,29 +53,25 @@ describe Gitlab::RedisConfig do
...
@@ -53,29 +53,25 @@ describe Gitlab::RedisConfig do
end
end
end
end
describe
'.raw_params'
do
describe
'#raw_config_hash'
do
subject
{
described_class
.
send
(
:raw_params
)
}
it
'returns default redis url when no config file is present'
do
it
'returns default redis url when no config file is present'
do
expect
(
Gitlab
::
RedisConfig
).
to
receive
(
:fetch_config
)
{
false
}
expect
(
subject
).
to
receive
(
:fetch_config
)
{
false
}
is_expected
.
to
eq
(
url:
Gitlab
::
RedisConfig
::
DEFAULT_REDIS_URL
)
expect
(
subject
.
send
(
:raw_config_hash
)).
to
eq
(
url:
Gitlab
::
Redis
::
DEFAULT_REDIS_URL
)
end
end
it
'returns old-style single url config in a hash'
do
it
'returns old-style single url config in a hash'
do
expect
(
Gitlab
::
RedisConfig
).
to
receive
(
:fetch_config
)
{
'redis://myredis:6379'
}
expect
(
subject
).
to
receive
(
:fetch_config
)
{
'redis://myredis:6379'
}
is_expected
.
to
eq
(
url:
'redis://myredis:6379'
)
expect
(
subject
.
send
(
:raw_config_hash
))
.
to
eq
(
url:
'redis://myredis:6379'
)
end
end
end
end
describe
'.fetch_config'
do
describe
'#fetch_config'
do
subject
{
described_class
.
send
(
:fetch_config
)
}
it
'returns false when no config file is present'
do
it
'returns false when no config file is present'
do
allow
(
File
).
to
receive
(
:exist
s
?
).
with
(
redis_config
)
{
false
}
allow
(
File
).
to
receive
(
:exist?
).
with
(
redis_config
)
{
false
}
is_expected
.
to
be_falsey
expect
(
subject
.
send
(
:fetch_config
))
.
to
be_falsey
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment