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
090f034b
Commit
090f034b
authored
Jul 04, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for RequestStoreWrap
parent
a4dd3ea1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
spec/lib/gitlab/cache/request_store_wrap_spec.rb
spec/lib/gitlab/cache/request_store_wrap_spec.rb
+99
-0
No files found.
spec/lib/gitlab/cache/request_store_wrap_spec.rb
0 → 100644
View file @
090f034b
require
'spec_helper'
describe
Gitlab
::
Cache
::
RequestStoreWrap
,
:request_store
do
class
ExpensiveAlgorithm
<
Struct
.
new
(
:id
,
:name
,
:result
)
extend
Gitlab
::
Cache
::
RequestStoreWrap
request_store_wrap_key
do
[
id
,
name
]
end
request_store_wrap
def
compute
(
arg
)
result
<<
arg
end
request_store_wrap
def
repute
(
arg
)
result
<<
arg
end
end
let
(
:algorithm
)
{
ExpensiveAlgorithm
.
new
(
'id'
,
'name'
,
[])
}
context
'when RequestStore is active'
do
it
'does not compute twice for the same argument'
do
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
])
expect
(
algorithm
.
compute
(
true
)).
to
eq
(
result
)
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different argument'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
false
)
expect
(
result
).
to
eq
([
true
,
false
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different keys, id'
do
algorithm
.
compute
(
true
)
algorithm
.
id
=
'ad'
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different keys, name'
do
algorithm
.
compute
(
true
)
algorithm
.
name
=
'same'
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different class name'
do
algorithm
.
compute
(
true
)
allow
(
ExpensiveAlgorithm
).
to
receive
(
:name
).
and_return
(
'CheapAlgo'
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different method'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
repute
(
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 RequestStore is inactive'
do
before
do
RequestStore
.
end!
end
it
'computes twice even if everything is the same'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
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