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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
5c9ba42e
Commit
5c9ba42e
authored
Feb 26, 2020
by
Sean Arnold
Committed by
Peter Leitzen
Feb 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for reactive cache set cache spec
Rename file too
parent
117e2614
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
5 deletions
+99
-5
app/models/concerns/reactive_caching.rb
app/models/concerns/reactive_caching.rb
+23
-0
app/models/error_tracking/project_error_tracking_setting.rb
app/models/error_tracking/project_error_tracking_setting.rb
+5
-1
app/services/error_tracking/issue_update_service.rb
app/services/error_tracking/issue_update_service.rb
+1
-0
lib/gitlab/reactive_cache_set_cache.rb
lib/gitlab/reactive_cache_set_cache.rb
+6
-2
spec/lib/gitlab/reactive_cache_set_cache_spec.rb
spec/lib/gitlab/reactive_cache_set_cache_spec.rb
+1
-1
spec/models/concerns/reactive_caching_spec.rb
spec/models/concerns/reactive_caching_spec.rb
+37
-0
spec/models/error_tracking/project_error_tracking_setting_spec.rb
...els/error_tracking/project_error_tracking_setting_spec.rb
+20
-1
spec/services/error_tracking/issue_update_service_spec.rb
spec/services/error_tracking/issue_update_service_spec.rb
+6
-0
No files found.
app/models/concerns/reactive_caching.rb
View file @
5c9ba42e
...
...
@@ -52,6 +52,13 @@ module ReactiveCaching
end
end
def
with_reactive_cache_set
(
resource
,
opts
,
&
blk
)
data
=
with_reactive_cache
(
resource
,
opts
,
&
blk
)
save_keys_in_set
(
resource
,
opts
)
if
data
data
end
# This method is used for debugging purposes and should not be used otherwise.
def
without_reactive_cache
(
*
args
,
&
blk
)
return
with_reactive_cache
(
*
args
,
&
blk
)
unless
Rails
.
env
.
development?
...
...
@@ -65,6 +72,12 @@ module ReactiveCaching
Rails
.
cache
.
delete
(
alive_reactive_cache_key
(
*
args
))
end
def
clear_reactive_cache_set!
(
*
args
)
cache_key
=
full_reactive_cache_key
(
args
)
reactive_set_cache
.
clear_cache!
(
cache_key
)
end
def
exclusively_update_reactive_cache!
(
*
args
)
locking_reactive_cache
(
*
args
)
do
key
=
full_reactive_cache_key
(
*
args
)
...
...
@@ -86,6 +99,16 @@ module ReactiveCaching
private
def
save_keys_in_set
(
resource
,
opts
)
cache_key
=
full_reactive_cache_key
(
resource
)
reactive_set_cache
.
write
(
cache_key
,
"
#{
cache_key
}
:
#{
opts
}
"
)
end
def
reactive_set_cache
Gitlab
::
ReactiveCacheSetCache
.
new
(
expires_in:
reactive_cache_lifetime
)
end
def
refresh_reactive_cache!
(
*
args
)
clear_reactive_cache!
(
*
args
)
keep_alive_reactive_cache!
(
*
args
)
...
...
app/models/error_tracking/project_error_tracking_setting.rb
View file @
5c9ba42e
...
...
@@ -85,7 +85,7 @@ module ErrorTracking
end
def
list_sentry_issues
(
opts
=
{})
with_reactive_cache
(
'list_issues'
,
opts
.
stringify_keys
)
do
|
result
|
with_reactive_cache
_set
(
'list_issues'
,
opts
.
stringify_keys
)
do
|
result
|
result
end
end
...
...
@@ -130,6 +130,10 @@ module ErrorTracking
end
end
def
expire_issues_cache
clear_reactive_cache_set!
(
'list_issues'
)
end
# http://HOST/api/0/projects/ORG/PROJECT
# ->
# http://HOST/ORG/PROJECT
...
...
app/services/error_tracking/issue_update_service.rb
View file @
5c9ba42e
...
...
@@ -11,6 +11,7 @@ module ErrorTracking
)
compose_response
(
response
)
do
project_error_tracking_setting
.
expire_issues_cache
response
[
:closed_issue_iid
]
=
update_related_issue
&
.
iid
end
end
...
...
lib/gitlab/reactive_cache_set_cache.rb
View file @
5c9ba42e
...
...
@@ -10,9 +10,13 @@ module Gitlab
@expires_in
=
expires_in
end
def
cache_key
(
key
)
"
#{
cache_type
}
:
#{
key
}
:set"
end
def
clear_cache!
(
key
)
with
do
|
redis
|
keys
=
read
(
key
).
map
{
|
value
|
"
#{
cache_type
}#{
value
}
"
}
keys
=
read
(
key
).
map
{
|
value
|
"
#{
cache_type
}
:
#{
value
}
"
}
keys
<<
cache_key
(
key
)
redis
.
pipelined
do
...
...
@@ -24,7 +28,7 @@ module Gitlab
private
def
cache_type
"
#{
Gitlab
::
Redis
::
Cache
::
CACHE_NAMESPACE
}
:"
Gitlab
::
Redis
::
Cache
::
CACHE_NAMESPACE
end
end
end
spec/lib/gitlab/reactive_cache_set_cache_spec.rb
View file @
5c9ba42e
...
...
@@ -12,7 +12,7 @@ describe Gitlab::ReactiveCacheSetCache, :clean_gitlab_redis_cache do
subject
{
cache
.
cache_key
(
cache_prefix
)
}
it
'includes the suffix'
do
expect
(
subject
).
to
eq
"
#{
cache_prefix
}
:set"
expect
(
subject
).
to
eq
"
#{
Gitlab
::
Redis
::
Cache
::
CACHE_NAMESPACE
}
:
#{
cache_prefix
}
:set"
end
end
...
...
spec/models/concerns/reactive_caching_spec.rb
View file @
5c9ba42e
...
...
@@ -112,6 +112,43 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
describe
'#with_reactive_cache_set'
,
:use_clean_rails_redis_caching
do
subject
(
:go!
)
do
instance
.
with_reactive_cache_set
(
'resource'
,
{})
do
|
data
|
data
end
end
it
'calls with_reactive_cache'
do
expect
(
instance
)
.
to
receive
(
:with_reactive_cache
)
go!
end
context
'data returned'
do
let
(
:resource
)
{
'resource'
}
let
(
:set_key
)
{
"
#{
cache_key
}
:
#{
resource
}
"
}
let
(
:set_cache
)
{
Gitlab
::
ReactiveCacheSetCache
.
new
}
before
do
stub_reactive_cache
(
instance
,
true
,
resource
,
{})
end
it
'saves keys in set'
do
expect
(
set_cache
.
read
(
set_key
)).
to
be_empty
go!
expect
(
set_cache
.
read
(
set_key
)).
not_to
be_empty
end
it
'returns the data'
do
expect
(
go!
).
to
eq
(
true
)
end
end
end
describe
'.reactive_cache_worker_finder'
do
context
'with default reactive_cache_worker_finder'
do
let
(
:args
)
{
%w(other args)
}
...
...
spec/models/error_tracking/project_error_tracking_setting_spec.rb
View file @
5c9ba42e
...
...
@@ -8,7 +8,7 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
let_it_be
(
:project
)
{
create
(
:project
)
}
subject
{
create
(
:project_error_tracking_setting
,
project:
project
)
}
subject
(
:setting
)
{
create
(
:project_error_tracking_setting
,
project:
project
)
}
describe
'Associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
...
...
@@ -453,4 +453,23 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
end
describe
'#expire_issues_cache'
,
:use_clean_rails_redis_caching
do
let
(
:issues
)
{
[
:some
,
:issues
]
}
let
(
:opt
)
{
'list_issues'
}
let
(
:params
)
{
{
issue_status:
'unresolved'
,
limit:
20
,
sort:
'last_seen'
}
}
before
do
start_reactive_cache_lifetime
(
subject
,
opt
,
params
.
stringify_keys
)
stub_reactive_cache
(
subject
,
issues
,
opt
,
params
.
stringify_keys
)
end
it
'clears the cache'
do
expect
(
subject
.
list_sentry_issues
(
params
)).
to
eq
(
issues
)
subject
.
expire_issues_cache
expect
(
subject
.
list_sentry_issues
(
params
)).
to
eq
(
nil
)
end
end
end
spec/services/error_tracking/issue_update_service_spec.rb
View file @
5c9ba42e
...
...
@@ -43,6 +43,12 @@ describe ErrorTracking::IssueUpdateService do
update_service
.
execute
end
it
'clears the reactive cache'
do
expect
(
error_tracking_setting
).
to
receive
(
:expire_issues_cache
)
result
end
context
'related issue and resolving'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:sentry_issue
)
{
create
(
:sentry_issue
,
issue:
issue
)
}
...
...
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