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
336635f2
Commit
336635f2
authored
May 22, 2017
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test the ExpireJobCacheWorker and related changes
These were untested by the cherry picked commit.
parent
da0c543e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
9 deletions
+50
-9
app/models/commit_status.rb
app/models/commit_status.rb
+1
-1
app/workers/expire_job_cache_worker.rb
app/workers/expire_job_cache_worker.rb
+6
-8
spec/models/commit_status_spec.rb
spec/models/commit_status_spec.rb
+10
-0
spec/workers/expire_job_cache_worker_spec.rb
spec/workers/expire_job_cache_worker_spec.rb
+31
-0
spec/workers/expire_pipeline_cache_worker_spec.rb
spec/workers/expire_pipeline_cache_worker_spec.rb
+2
-0
No files found.
app/models/commit_status.rb
View file @
336635f2
...
...
@@ -89,7 +89,7 @@ class CommitStatus < ActiveRecord::Base
else
PipelineUpdateWorker
.
perform_async
(
pipeline
.
id
)
end
ExpireJobCacheWorker
.
perform_async
(
pipeline
.
id
,
commit_status
.
id
)
ExpireJobCacheWorker
.
perform_async
(
commit_status
.
id
)
end
end
end
...
...
app/workers/expire_job_cache_worker.rb
View file @
336635f2
...
...
@@ -2,15 +2,17 @@ class ExpireJobCacheWorker
include
Sidekiq
::
Worker
include
BuildQueue
def
perform
(
pipeline_id
,
job_id
)
job
=
CommitStatus
.
joins
(
:pipeline
,
:project
).
find_by
(
id:
job
)
def
perform
(
job_id
)
job
=
CommitStatus
.
joins
(
:pipeline
,
:project
).
find_by
(
id:
job
_id
)
return
unless
job
pipeline
=
job
.
pipeline
project
=
job
.
project
store
.
touch
(
project_pipeline_path
(
project
,
pipeline
))
store
.
touch
(
project_job_path
(
project
,
job
))
Gitlab
::
EtagCaching
::
Store
.
new
.
tap
do
|
store
|
store
.
touch
(
project_pipeline_path
(
project
,
pipeline
))
store
.
touch
(
project_job_path
(
project
,
job
))
end
end
private
...
...
@@ -30,8 +32,4 @@ class ExpireJobCacheWorker
job
.
id
,
format: :json
)
end
def
store
@store
||=
Gitlab
::
EtagCaching
::
Store
.
new
end
end
spec/models/commit_status_spec.rb
View file @
336635f2
...
...
@@ -36,6 +36,16 @@ describe CommitStatus, :models do
it
{
is_expected
.
to
eq
(
commit_status
.
user
)
}
end
describe
'status state machine'
do
let!
(
:commit_status
)
{
create
(
:commit_status
,
:running
,
project:
project
)
}
it
'invalidates the cache after a transition'
do
expect
(
ExpireJobCacheWorker
).
to
receive
(
:perform_async
).
with
(
commit_status
.
id
)
commit_status
.
success!
end
end
describe
'#started?'
do
subject
{
commit_status
.
started?
}
...
...
spec/workers/expire_job_cache_worker_spec.rb
0 → 100644
View file @
336635f2
require
'spec_helper'
describe
ExpireJobCacheWorker
do
set
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:project
)
{
pipeline
.
project
}
subject
{
described_class
.
new
}
describe
'#perform'
do
context
'with a job in the pipeline'
do
let
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'invalidates Etag caching for the job path'
do
pipeline_path
=
"/
#{
project
.
full_path
}
/pipelines/
#{
pipeline
.
id
}
.json"
job_path
=
"/
#{
project
.
full_path
}
/builds/
#{
job
.
id
}
.json"
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipeline_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
job_path
)
subject
.
perform
(
job
.
id
)
end
end
context
'when there is no job in the pipeline'
do
it
'does not change the etag store'
do
expect
(
Gitlab
::
EtagCaching
::
Store
).
not_to
receive
(
:new
)
subject
.
perform
(
9999
)
end
end
end
end
spec/workers/expire_pipeline_cache_worker_spec.rb
View file @
336635f2
...
...
@@ -10,9 +10,11 @@ describe ExpirePipelineCacheWorker do
it
'invalidates Etag caching for project pipelines path'
do
pipelines_path
=
"/
#{
project
.
full_path
}
/pipelines.json"
new_mr_pipelines_path
=
"/
#{
project
.
full_path
}
/merge_requests/new.json"
pipeline_path
=
"/
#{
project
.
full_path
}
/pipelines/
#{
pipeline
.
id
}
.json"
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
new_mr_pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipeline_path
)
subject
.
perform
(
pipeline
.
id
)
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