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
Jérome Perrin
gitlab-ce
Commits
a0497a7b
Commit
a0497a7b
authored
May 25, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move helpers to spec file, use const's instead of helper methods
parent
8067efdf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
35 deletions
+26
-35
lib/gitlab/health_checks/fs_shards_check.rb
lib/gitlab/health_checks/fs_shards_check.rb
+4
-8
spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
+22
-8
spec/support/timeout_helper.rb
spec/support/timeout_helper.rb
+0
-19
No files found.
lib/gitlab/health_checks/fs_shards_check.rb
View file @
a0497a7b
...
@@ -2,6 +2,9 @@ module Gitlab
...
@@ -2,6 +2,9 @@ module Gitlab
module
HealthChecks
module
HealthChecks
class
FsShardsCheck
class
FsShardsCheck
extend
BaseAbstractCheck
extend
BaseAbstractCheck
RANDOM_STRING
=
SecureRandom
.
hex
(
1000
).
freeze
COMMAND_TIMEOUT
=
'1'
.
freeze
TIMEOUT_EXECUTABLE
=
'timeout'
.
freeze
class
<<
self
class
<<
self
def
readiness
def
readiness
...
@@ -41,9 +44,6 @@ module Gitlab
...
@@ -41,9 +44,6 @@ module Gitlab
private
private
RANDOM_STRING
=
SecureRandom
.
hex
(
1000
).
freeze
COMMAND_TIMEOUT
=
1
.
second
def
operation_metrics
(
ok_metric
,
latency_metric
,
operation
,
**
labels
)
def
operation_metrics
(
ok_metric
,
latency_metric
,
operation
,
**
labels
)
with_timing
operation
do
|
result
,
elapsed
|
with_timing
operation
do
|
result
,
elapsed
|
[
[
...
@@ -64,12 +64,8 @@ module Gitlab
...
@@ -64,12 +64,8 @@ module Gitlab
@storage_paths
||=
Gitlab
.
config
.
repositories
.
storages
@storage_paths
||=
Gitlab
.
config
.
repositories
.
storages
end
end
def
with_timeout
(
args
)
%W{timeout
#{
COMMAND_TIMEOUT
.
to_i
}
}
.
concat
(
args
)
end
def
exec_with_timeout
(
cmd_args
,
*
args
,
&
block
)
def
exec_with_timeout
(
cmd_args
,
*
args
,
&
block
)
Gitlab
::
Popen
.
popen
(
with_timeou
t
(
cmd_args
),
*
args
,
&
block
)
Gitlab
::
Popen
.
popen
(
[
TIMEOUT_EXECUTABLE
,
COMMAND_TIMEOUT
].
conca
t
(
cmd_args
),
*
args
,
&
block
)
end
end
def
tmp_file_path
(
storage_name
)
def
tmp_file_path
(
storage_name
)
...
...
spec/lib/gitlab/health_checks/fs_shards_check_spec.rb
View file @
a0497a7b
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
HealthChecks
::
FsShardsCheck
do
describe
Gitlab
::
HealthChecks
::
FsShardsCheck
do
include
TimeoutHelper
def
command_exists?
(
command
)
_
,
status
=
Gitlab
::
Popen
.
popen
(
%W{
#{
command
}
1 echo }
)
status
==
0
rescue
Errno
::
ENOENT
false
end
def
timeout_command
@timeout_command
||=
if
command_exists?
(
'timeout'
)
'timeout'
elsif
command_exists?
(
'gtimeout'
)
'gtimeout'
else
''
end
end
let
(
:metric_class
)
{
Gitlab
::
HealthChecks
::
Metric
}
let
(
:metric_class
)
{
Gitlab
::
HealthChecks
::
Metric
}
let
(
:result_class
)
{
Gitlab
::
HealthChecks
::
Result
}
let
(
:result_class
)
{
Gitlab
::
HealthChecks
::
Result
}
...
@@ -17,6 +33,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
...
@@ -17,6 +33,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
before
do
before
do
allow
(
described_class
).
to
receive
(
:repository_storages
)
{
repository_storages
}
allow
(
described_class
).
to
receive
(
:repository_storages
)
{
repository_storages
}
allow
(
described_class
).
to
receive
(
:storages_paths
)
{
storages_paths
}
allow
(
described_class
).
to
receive
(
:storages_paths
)
{
storages_paths
}
stub_const
(
'Gitlab::HealthChecks::FsShardsCheck::TIMEOUT_EXECUTABLE'
,
timeout_command
)
end
end
after
do
after
do
...
@@ -109,10 +126,10 @@ describe Gitlab::HealthChecks::FsShardsCheck do
...
@@ -109,10 +126,10 @@ describe Gitlab::HealthChecks::FsShardsCheck do
end
end
context
'when timeout kills fs checks'
do
context
'when timeout kills fs checks'
do
let
(
:timeout_seconds
)
{
1
.
to_s
}
before
do
before
do
allow
(
described_class
).
to
receive
(
:with_timeout
)
{
[
timeout_command
,
timeout_seconds
,
'sleep'
,
'20'
]
}
stub_const
(
'Gitlab::HealthChecks::FsShardsCheck::COMMAND_TIMEOUT'
,
'1'
)
allow
(
described_class
).
to
receive
(
:exec_with_timeout
).
and_wrap_original
{
|
m
|
m
.
call
(
%w(sleep 60)
)
}
FileUtils
.
chmod_R
(
0755
,
tmp_dir
)
FileUtils
.
chmod_R
(
0755
,
tmp_dir
)
end
end
...
@@ -140,7 +157,6 @@ describe Gitlab::HealthChecks::FsShardsCheck do
...
@@ -140,7 +157,6 @@ describe Gitlab::HealthChecks::FsShardsCheck do
end
end
context
'when popen always finds required binaries'
do
context
'when popen always finds required binaries'
do
let
(
:timeout_seconds
)
{
30
.
to_s
}
before
do
before
do
allow
(
described_class
).
to
receive
(
:exec_with_timeout
).
and_wrap_original
do
|
method
,
*
args
,
&
block
|
allow
(
described_class
).
to
receive
(
:exec_with_timeout
).
and_wrap_original
do
|
method
,
*
args
,
&
block
|
begin
begin
...
@@ -150,9 +166,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
...
@@ -150,9 +166,7 @@ describe Gitlab::HealthChecks::FsShardsCheck do
end
end
end
end
allow
(
described_class
).
to
receive
(
:with_timeout
)
do
|
args
,
&
block
|
stub_const
(
'Gitlab::HealthChecks::FsShardsCheck::COMMAND_TIMEOUT'
,
'10'
)
[
timeout_command
,
timeout_seconds
].
concat
(
args
)
end
end
end
it_behaves_like
'filesystem checks'
it_behaves_like
'filesystem checks'
...
...
spec/support/timeout_helper.rb
deleted
100644 → 0
View file @
8067efdf
module
TimeoutHelper
def
command_exists?
(
command
)
_
,
status
=
Gitlab
::
Popen
.
popen
(
%W{
#{
command
}
1 echo }
)
status
==
0
rescue
Errno
::
ENOENT
false
end
def
timeout_command
@timeout_command
||=
if
command_exists?
(
'timeout'
)
'timeout'
elsif
command_exists?
(
'gtimeout'
)
'gtimeout'
else
''
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