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
8dbb228b
Commit
8dbb228b
authored
Sep 06, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rails cache spec
parent
39ac6acb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
28 deletions
+29
-28
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
+29
-28
No files found.
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
View file @
8dbb228b
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Subscribers
::
RailsCache
do
describe
Gitlab
::
Metrics
::
Subscribers
::
RailsCache
do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
env
)
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
{
double
(
:event
,
duration:
15.2
)
}
let
(
:event
)
{
double
(
:event
,
duration:
15.2
)
}
describe
'#cache_read'
do
describe
'#cache_read'
do
it
'increments the cache_read duration'
do
it
'increments the cache_read duration'
do
expect
(
subscriber
).
to
receive
(
:
increment
)
expect
(
subscriber
).
to
receive
(
:
observe
)
.
with
(
:cache_
read
,
event
.
duration
)
.
with
(
:
read
,
event
.
duration
)
subscriber
.
cache_read
(
event
)
subscriber
.
cache_read
(
event
)
end
end
...
@@ -17,7 +18,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -17,7 +18,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
context
'with a transaction'
do
context
'with a transaction'
do
before
do
before
do
allow
(
subscriber
).
to
receive
(
:current_transaction
)
allow
(
subscriber
).
to
receive
(
:current_transaction
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
end
end
context
'with hit event'
do
context
'with hit event'
do
...
@@ -25,9 +26,9 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -25,9 +26,9 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it
'increments the cache_read_hit count'
do
it
'increments the cache_read_hit count'
do
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_read_hit_count
,
1
)
.
with
(
:cache_read_hit_count
,
1
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
any_args
).
at_least
(
1
)
# Other calls
.
with
(
any_args
).
at_least
(
1
)
# Other calls
subscriber
.
cache_read
(
event
)
subscriber
.
cache_read
(
event
)
end
end
...
@@ -37,7 +38,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -37,7 +38,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it
'does not increment cache read miss'
do
it
'does not increment cache read miss'
do
expect
(
transaction
).
not_to
receive
(
:increment
)
expect
(
transaction
).
not_to
receive
(
:increment
)
.
with
(
:cache_read_hit_count
,
1
)
.
with
(
:cache_read_hit_count
,
1
)
subscriber
.
cache_read
(
event
)
subscriber
.
cache_read
(
event
)
end
end
...
@@ -49,9 +50,9 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -49,9 +50,9 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it
'increments the cache_read_miss count'
do
it
'increments the cache_read_miss count'
do
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_read_miss_count
,
1
)
.
with
(
:cache_read_miss_count
,
1
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
any_args
).
at_least
(
1
)
# Other calls
.
with
(
any_args
).
at_least
(
1
)
# Other calls
subscriber
.
cache_read
(
event
)
subscriber
.
cache_read
(
event
)
end
end
...
@@ -61,7 +62,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -61,7 +62,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
it
'does not increment cache read miss'
do
it
'does not increment cache read miss'
do
expect
(
transaction
).
not_to
receive
(
:increment
)
expect
(
transaction
).
not_to
receive
(
:increment
)
.
with
(
:cache_read_miss_count
,
1
)
.
with
(
:cache_read_miss_count
,
1
)
subscriber
.
cache_read
(
event
)
subscriber
.
cache_read
(
event
)
end
end
...
@@ -72,8 +73,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -72,8 +73,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe
'#cache_write'
do
describe
'#cache_write'
do
it
'increments the cache_write duration'
do
it
'increments the cache_write duration'
do
expect
(
subscriber
).
to
receive
(
:
increment
)
expect
(
subscriber
).
to
receive
(
:
observe
)
.
with
(
:cache_
write
,
event
.
duration
)
.
with
(
:
write
,
event
.
duration
)
subscriber
.
cache_write
(
event
)
subscriber
.
cache_write
(
event
)
end
end
...
@@ -81,8 +82,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -81,8 +82,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe
'#cache_delete'
do
describe
'#cache_delete'
do
it
'increments the cache_delete duration'
do
it
'increments the cache_delete duration'
do
expect
(
subscriber
).
to
receive
(
:
increment
)
expect
(
subscriber
).
to
receive
(
:
observe
)
.
with
(
:cache_
delete
,
event
.
duration
)
.
with
(
:
delete
,
event
.
duration
)
subscriber
.
cache_delete
(
event
)
subscriber
.
cache_delete
(
event
)
end
end
...
@@ -90,8 +91,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -90,8 +91,8 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
describe
'#cache_exist?'
do
describe
'#cache_exist?'
do
it
'increments the cache_exists duration'
do
it
'increments the cache_exists duration'
do
expect
(
subscriber
).
to
receive
(
:
increment
)
expect
(
subscriber
).
to
receive
(
:
observe
)
.
with
(
:cache_
exists
,
event
.
duration
)
.
with
(
:
exists
,
event
.
duration
)
subscriber
.
cache_exist?
(
event
)
subscriber
.
cache_exist?
(
event
)
end
end
...
@@ -109,12 +110,12 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -109,12 +110,12 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
context
'with a transaction'
do
context
'with a transaction'
do
before
do
before
do
allow
(
subscriber
).
to
receive
(
:current_transaction
)
allow
(
subscriber
).
to
receive
(
:current_transaction
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
end
end
it
'increments the cache_read_hit count'
do
it
'increments the cache_read_hit count'
do
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_read_hit_count
,
1
)
.
with
(
:cache_read_hit_count
,
1
)
subscriber
.
cache_fetch_hit
(
event
)
subscriber
.
cache_fetch_hit
(
event
)
end
end
...
@@ -133,47 +134,47 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
...
@@ -133,47 +134,47 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
context
'with a transaction'
do
context
'with a transaction'
do
before
do
before
do
allow
(
subscriber
).
to
receive
(
:current_transaction
)
allow
(
subscriber
).
to
receive
(
:current_transaction
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
end
end
it
'increments the cache_fetch_miss count'
do
it
'increments the cache_fetch_miss count'
do
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_read_miss_count
,
1
)
.
with
(
:cache_read_miss_count
,
1
)
subscriber
.
cache_generate
(
event
)
subscriber
.
cache_generate
(
event
)
end
end
end
end
end
end
describe
'#
increment
'
do
describe
'#
observe
'
do
context
'without a transaction'
do
context
'without a transaction'
do
it
'returns'
do
it
'returns'
do
expect
(
transaction
).
not_to
receive
(
:increment
)
expect
(
transaction
).
not_to
receive
(
:increment
)
subscriber
.
increment
(
:foo
,
15.2
)
subscriber
.
observe
(
:foo
,
15.2
)
end
end
end
end
context
'with a transaction'
do
context
'with a transaction'
do
before
do
before
do
allow
(
subscriber
).
to
receive
(
:current_transaction
)
allow
(
subscriber
).
to
receive
(
:current_transaction
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
end
end
it
'increments the total and specific cache duration'
do
it
'increments the total and specific cache duration'
do
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_duration
,
event
.
duration
)
.
with
(
:cache_duration
,
event
.
duration
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_count
,
1
)
.
with
(
:cache_count
,
1
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_delete_duration
,
event
.
duration
)
.
with
(
:cache_delete_duration
,
event
.
duration
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:cache_delete_count
,
1
)
.
with
(
:cache_delete_count
,
1
,
false
)
subscriber
.
increment
(
:cache_
delete
,
event
.
duration
)
subscriber
.
observe
(
:
delete
,
event
.
duration
)
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