BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
67fcd061
Commit
67fcd061
authored
Jan 18, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test if feature is respected
parent
afeb7ce9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
21 deletions
+54
-21
metric_options.rb
lib/gitlab/metrics/concern/metric_options.rb
+2
-2
concern_spec.rb
spec/lib/gitlab/metrics/concern_spec.rb
+52
-19
No files found.
lib/gitlab/metrics/concern/metric_options.rb
View file @
67fcd061
...
@@ -44,9 +44,9 @@ module Gitlab
...
@@ -44,9 +44,9 @@ module Gitlab
# Use feature toggle to control whether certain metric is enabled/disabled
# Use feature toggle to control whether certain metric is enabled/disabled
def
with_feature
(
name
=
nil
)
def
with_feature
(
name
=
nil
)
@
feature_nam
e
=
name
unless
name
.
nil?
@
with_featur
e
=
name
unless
name
.
nil?
@
feature_nam
e
@
with_featur
e
end
end
def
evaluate
(
&
block
)
def
evaluate
(
&
block
)
...
...
spec/lib/gitlab/metrics/concern_spec.rb
View file @
67fcd061
...
@@ -5,47 +5,47 @@ describe Gitlab::Metrics::Concern do
...
@@ -5,47 +5,47 @@ describe Gitlab::Metrics::Concern do
shared_context
'metric'
do
|
metric_type
,
*
args
|
shared_context
'metric'
do
|
metric_type
,
*
args
|
let
(
:docstring
)
{
'description'
}
let
(
:docstring
)
{
'description'
}
let
(
:metric
)
{
:sample_metric
}
let
(
:metric
_name
)
{
:sample_metric
}
describe
"#define_
#{
metric_type
}
"
do
describe
"#define_
#{
metric_type
}
"
do
let
(
:define_method
)
{
"define_
#{
metric_type
}
"
.
to_sym
}
let
(
:define_method
)
{
"define_
#{
metric_type
}
"
.
to_sym
}
context
'metrics access method not defined'
do
context
'metrics access method not defined'
do
it
"defines metrics accessing method"
do
it
"defines metrics accessing method"
do
expect
(
subject
).
not_to
respond_to
(
metric
)
expect
(
subject
).
not_to
respond_to
(
metric
_name
)
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
expect
(
subject
).
to
respond_to
(
metric
)
expect
(
subject
).
to
respond_to
(
metric
_name
)
end
end
end
end
context
'metrics access method defined'
do
context
'metrics access method defined'
do
before
do
before
do
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
end
end
it
'raises error when trying to redefine method'
do
it
'raises error when trying to redefine method'
do
expect
{
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
expect
{
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
end
end
context
'metric is not cached'
do
context
'metric is not cached'
do
it
'calls fetch_metric'
do
it
'calls fetch_metric'
do
expect
(
subject
).
to
receive
(
:fetch_metric
).
with
(
metric_type
,
metric
,
docstring:
docstring
)
expect
(
subject
).
to
receive
(
:fetch_metric
).
with
(
metric_type
,
metric
_name
,
docstring:
docstring
)
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
end
end
end
context
'metric is cached'
do
context
'metric is cached'
do
before
do
before
do
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
end
it
'returns cached metric'
do
it
'returns cached metric'
do
expect
(
subject
).
not_to
receive
(
:fetch_metric
)
expect
(
subject
).
not_to
receive
(
:fetch_metric
)
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
end
end
end
end
end
...
@@ -55,38 +55,71 @@ describe Gitlab::Metrics::Concern do
...
@@ -55,38 +55,71 @@ describe Gitlab::Metrics::Concern do
let
(
:fetch_method
)
{
"fetch_
#{
metric_type
}
"
.
to_sym
}
let
(
:fetch_method
)
{
"fetch_
#{
metric_type
}
"
.
to_sym
}
let
(
:null_metric
)
{
Gitlab
::
Metrics
::
NullMetric
.
new
}
let
(
:null_metric
)
{
Gitlab
::
Metrics
::
NullMetric
.
new
}
context
"when
#{
metric_type
}
fetched first time
"
do
context
"when
#{
metric_type
}
is not cached
"
do
it
'initializes counter metric'
do
it
'initializes counter metric'
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
,
docstring
,
*
args
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
_name
,
docstring
,
*
args
)
end
end
end
end
context
"when
#{
metric_type
}
is
fetched second time
"
do
context
"when
#{
metric_type
}
is
cached
"
do
before
do
before
do
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
end
end
it
'uses class metric cache'
do
it
'uses class metric cache'
do
expect
(
Gitlab
::
Metrics
).
not_to
receive
(
metric_type
)
expect
(
Gitlab
::
Metrics
).
not_to
receive
(
metric_type
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
end
end
context
'when metric is reloaded'
do
context
'when metric is reloaded'
do
before
do
before
do
subject
.
reload_metric!
(
metric
)
subject
.
reload_metric!
(
metric
_name
)
end
end
it
"initializes
#{
metric_type
}
metric"
do
it
"initializes
#{
metric_type
}
metric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
,
docstring
,
*
args
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
end
end
context
'when metric is configured with feature'
do
let
(
:feature_name
)
{
:some_metric_feature
}
let
(
:metric
)
{
subject
.
send
(
fetch_method
,
metric_name
,
docstring:
docstring
,
with_feature:
feature_name
)
}
context
'when feature is enabled'
do
before
do
Feature
.
get
(
feature_name
).
enable
end
it
"initializes
#{
metric_type
}
metric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
metric
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
end
context
'when feature is disabled'
do
before
do
Feature
.
get
(
feature_name
).
disable
end
it
"returns NullMetric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
expect
(
metric
).
to
be_instance_of
(
Gitlab
::
Metrics
::
NullMetric
)
expect
(
Gitlab
::
Metrics
).
not_to
have_received
(
metric_type
)
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