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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
aa57a76f
Commit
aa57a76f
authored
Jul 19, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rescue database errors / connection for Geo.enabled? and return false
parent
b05f9e0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletion
+61
-1
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+6
-1
spec/lib/gitlab/geo_spec.rb
spec/lib/gitlab/geo_spec.rb
+55
-0
No files found.
lib/gitlab/geo.rb
View file @
aa57a76f
...
@@ -31,7 +31,12 @@ module Gitlab
...
@@ -31,7 +31,12 @@ module Gitlab
end
end
def
self
.
enabled?
def
self
.
enabled?
self
.
cache_value
(
:geo_node_enabled
)
{
GeoNode
.
exists?
}
GeoNode
.
connected?
&&
self
.
cache_value
(
:geo_node_enabled
)
{
GeoNode
.
exists?
}
rescue
=>
e
# We can't use the actual classes in rescue because we load only one of them based on database supported
raise
e
unless
%w(PG::UndefinedTable Mysql2::Error)
.
include?
e
.
class
.
name
false
end
end
def
self
.
current_node_enabled?
def
self
.
current_node_enabled?
...
...
spec/lib/gitlab/geo_spec.rb
View file @
aa57a76f
...
@@ -25,6 +25,43 @@ describe Gitlab::Geo, lib: true do
...
@@ -25,6 +25,43 @@ describe Gitlab::Geo, lib: true do
end
end
end
end
describe
'primary?'
do
context
'when current node is a primary node'
do
before
(
:each
)
do
primary_node
end
it
'returns true'
do
expect
(
described_class
.
primary?
).
to
be_truthy
end
it
'returns false when GeoNode is disabled'
do
allow
(
described_class
).
to
receive
(
:enabled?
)
{
false
}
expect
(
described_class
.
primary?
).
to
be_falsey
end
end
end
describe
'secondary?'
do
context
'when current node is a secondary node'
do
before
(
:each
)
do
secondary_node
allow
(
described_class
).
to
receive
(
:current_node
)
{
secondary_node
}
end
it
'returns true'
do
expect
(
described_class
.
secondary?
).
to
be_truthy
end
it
'returns false when GeoNode is disabled'
do
allow
(
described_class
).
to
receive
(
:enabled?
)
{
false
}
expect
(
described_class
.
secondary?
).
to
be_falsey
end
end
end
describe
'enabled?'
do
describe
'enabled?'
do
context
'when any GeoNode exists'
do
context
'when any GeoNode exists'
do
before
do
before
do
...
@@ -42,6 +79,24 @@ describe Gitlab::Geo, lib: true do
...
@@ -42,6 +79,24 @@ describe Gitlab::Geo, lib: true do
end
end
end
end
context
'when there is a database issue'
do
it
'returns false when database connection is down'
do
allow
(
GeoNode
).
to
receive
(
:connected?
)
{
false
}
expect
(
described_class
.
enabled?
).
to
be_falsey
end
it
'returns false when database schema does not contain required tables'
do
if
Gitlab
::
Database
.
mysql?
allow
(
GeoNode
).
to
receive
(
:exists?
).
and_raise
(
Mysql2
::
Error
)
else
allow
(
GeoNode
).
to
receive
(
:exists?
).
and_raise
(
PG
::
UndefinedTable
)
end
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
context
'with RequestStore enabled'
do
context
'with RequestStore enabled'
do
before
do
before
do
RequestStore
.
begin!
RequestStore
.
begin!
...
...
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