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
f69c0f80
Commit
f69c0f80
authored
Jul 18, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unneeded asserts and add tests for inactive RequestStore
parent
3922b803
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
28 deletions
+20
-28
spec/lib/gitlab/cache/request_cache_spec.rb
spec/lib/gitlab/cache/request_cache_spec.rb
+20
-28
No files found.
spec/lib/gitlab/cache/request_cache_spec.rb
View file @
f69c0f80
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Cache
::
RequestCache
,
:request_store
do
describe
Gitlab
::
Cache
::
RequestCache
do
let
(
:klass
)
do
let
(
:klass
)
do
Class
.
new
do
Class
.
new
do
extend
Gitlab
::
Cache
::
RequestCache
extend
Gitlab
::
Cache
::
RequestCache
...
@@ -35,13 +35,12 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -35,13 +35,12 @@ describe Gitlab::Cache::RequestCache, :request_store do
let
(
:algorithm
)
{
klass
.
new
(
'id'
,
'name'
,
[])
}
let
(
:algorithm
)
{
klass
.
new
(
'id'
,
'name'
,
[])
}
context
'when RequestStore is activ
e'
do
shared_examples
'cache for the same instanc
e'
do
it
'does not compute twice for the same argument'
do
it
'does not compute twice for the same argument'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
])
expect
(
result
).
to
eq
([
true
])
expect
(
algorithm
.
compute
(
true
)).
to
eq
(
result
)
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
it
'computes twice for the different argument'
do
it
'computes twice for the different argument'
do
...
@@ -49,7 +48,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -49,7 +48,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
compute
(
false
)
result
=
algorithm
.
compute
(
false
)
expect
(
result
).
to
eq
([
true
,
false
])
expect
(
result
).
to
eq
([
true
,
false
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
it
'computes twice for the different class name'
do
it
'computes twice for the different class name'
do
...
@@ -58,7 +56,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -58,7 +56,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
it
'computes twice for the different method'
do
it
'computes twice for the different method'
do
...
@@ -66,18 +63,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -66,18 +63,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
repute
(
true
)
result
=
algorithm
.
repute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice if RequestStore starts over'
do
algorithm
.
compute
(
true
)
RequestStore
.
end!
RequestStore
.
clear!
RequestStore
.
begin!
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
context
'when request_cache_key is provided'
do
context
'when request_cache_key is provided'
do
...
@@ -93,7 +78,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -93,7 +78,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
it
'computes twice for the different keys, name'
do
it
'computes twice for the different keys, name'
do
...
@@ -102,7 +86,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -102,7 +86,6 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
it
'uses extra method cache key if provided'
do
it
'uses extra method cache key if provided'
do
...
@@ -112,30 +95,39 @@ describe Gitlab::Cache::RequestCache, :request_store do
...
@@ -112,30 +95,39 @@ describe Gitlab::Cache::RequestCache, :request_store do
result
=
algorithm
.
dispute
(
true
)
# hit
result
=
algorithm
.
dispute
(
true
)
# hit
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
end
end
end
end
context
'when RequestStore is inactive'
do
context
'when RequestStore is active'
,
:request_store
do
before
do
it_behaves_like
'cache for the same instance'
RequestStore
.
end!
it
'computes once for different instances when keys are the same'
do
algorithm
.
compute
(
true
)
result
=
klass
.
new
(
'id'
,
'name'
,
algorithm
.
result
).
compute
(
true
)
expect
(
result
).
to
eq
([
true
])
end
end
it
'computes
only once if it is the same instance for the same key
'
do
it
'computes
twice if RequestStore starts over
'
do
algorithm
.
compute
(
true
)
algorithm
.
compute
(
true
)
RequestStore
.
end!
RequestStore
.
clear!
RequestStore
.
begin!
result
=
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
end
context
'when RequestStore is inactive'
do
it_behaves_like
'cache for the same instance'
it
'computes twice for different instances even if keys are the same'
do
it
'computes twice for different instances even if keys are the same'
do
algorithm
.
compute
(
true
)
algorithm
.
compute
(
true
)
result
=
klass
.
new
(
'id'
,
'name'
,
algorithm
.
result
).
compute
(
true
)
result
=
klass
.
new
(
'id'
,
'name'
,
algorithm
.
result
).
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
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