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
32f825c6
Commit
32f825c6
authored
Jun 01, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for each new code
parent
10acdc30
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
13 deletions
+90
-13
app/models/ci/build_trace_chunk.rb
app/models/ci/build_trace_chunk.rb
+1
-1
spec/lib/gitlab/ci/trace_spec.rb
spec/lib/gitlab/ci/trace_spec.rb
+1
-1
spec/models/ci/build_trace_chunk_spec.rb
spec/models/ci/build_trace_chunk_spec.rb
+40
-0
spec/support/shared_examples/ci_trace_shared_examples.rb
spec/support/shared_examples/ci_trace_shared_examples.rb
+25
-0
spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
+23
-11
No files found.
app/models/ci/build_trace_chunk.rb
View file @
32f825c6
...
...
@@ -60,7 +60,7 @@ module Ci
.
merge
(
Ci
::
Build
.
finished
)
.
where
(
'ci_builds.finished_at < ?'
,
finished_before
)
.
each_batch
(
column: :build_id
)
do
|
chunks
|
build_ids
=
chunks
.
map
{
|
chunk
|
[
chunk
.
build_id
]
}
build_ids
=
chunks
.
map
{
|
chunk
|
chunk
.
build_id
}
yield
build_ids
end
...
...
spec/lib/gitlab/ci/trace_spec.rb
View file @
32f825c6
require
'spec_helper'
describe
Gitlab
::
Ci
::
Trace
,
:clean_gitlab_redis_
cach
e
do
describe
Gitlab
::
Ci
::
Trace
,
:clean_gitlab_redis_
shared_stat
e
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:trace
)
{
described_class
.
new
(
build
)
}
...
...
spec/models/ci/build_trace_chunk_spec.rb
View file @
32f825c6
...
...
@@ -35,6 +35,46 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
end
end
describe
'.find_stale_in_batches'
do
subject
{
described_class
.
find_stale_in_batches
}
context
'when build status is finished'
do
context
'when build finished 2 days ago'
do
context
'when build has an archived trace'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:trace_artifact
,
finished_at:
2
.
days
.
ago
)
}
it
'does not yield build id'
do
expect
{
|
b
|
described_class
.
find_stale_in_batches
(
&
b
)
}.
not_to
yield_control
end
end
context
'when build has a live trace'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:trace_live
,
finished_at:
2
.
days
.
ago
)
}
it
'yields build id'
do
expect
{
|
b
|
described_class
.
find_stale_in_batches
(
&
b
)
}.
to
yield_with_args
([
build
.
id
])
end
end
end
context
'when build finished 10 minutes ago'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:trace_live
,
finished_at:
10
.
minutes
.
ago
)
}
it
'does not yield build id'
do
expect
{
|
b
|
described_class
.
find_stale_in_batches
(
&
b
)
}.
not_to
yield_control
end
end
end
context
'when build status is running'
do
let!
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
)
}
it
'does not yield build id'
do
expect
{
|
b
|
described_class
.
find_stale_in_batches
(
&
b
)
}.
not_to
yield_control
end
end
end
describe
'#data'
do
subject
{
build_trace_chunk
.
data
}
...
...
spec/support/shared_examples/ci_trace_shared_examples.rb
View file @
32f825c6
...
...
@@ -227,6 +227,31 @@ shared_examples_for 'common trace features' do
end
end
end
describe
'#archive!'
do
subject
{
trace
.
archive!
}
context
'when build status is success'
do
let!
(
:build
)
{
create
(
:ci_build
,
:success
,
:trace_live
)
}
it
'archives a trace'
do
subject
expect
(
build
.
job_artifacts_trace
).
to
be_exist
end
context
'when anothe process had already been archiving'
,
:clean_gitlab_redis_shared_state
do
before
do
Gitlab
::
ExclusiveLease
.
new
(
"trace:archive:
#{
trace
.
job
.
id
}
"
,
timeout:
1
.
hour
).
try_obtain
end
it
'prevents multiple archiving'
do
build
.
reload
expect
(
build
.
job_artifacts_trace
).
to
be_nil
end
end
end
end
end
shared_examples_for
'trace with disabled live trace feature'
do
...
...
spec/workers/ci/rescue_stale_live_trace_worker_spec.rb
View file @
32f825c6
...
...
@@ -7,19 +7,20 @@ describe Ci::RescueStaleLiveTraceWorker do
stub_feature_flags
(
ci_enable_live_trace:
true
)
end
shared_examples_for
'
schedules to archive traces
'
do
shared_examples_for
'
archives trace
'
do
it
do
expect
(
ArchiveTraceWorker
).
to
receive
(
:bulk_perform_async
).
with
([[
build
.
id
]])
subject
expect
(
build
.
job_artifacts_trace
).
to
be_exist
end
end
shared_examples_for
'does not
schedule to archive traces
'
do
shared_examples_for
'does not
archive trace
'
do
it
do
expect
(
ArchiveTraceWorker
).
not_to
receive
(
:bulk_perform_async
)
subject
build
.
reload
expect
(
build
.
job_artifacts_trace
).
to
be_nil
end
end
...
...
@@ -30,7 +31,18 @@ describe Ci::RescueStaleLiveTraceWorker do
build
.
update
(
finished_at:
2
.
hours
.
ago
)
end
it_behaves_like
'schedules to archive traces'
it_behaves_like
'archives trace'
context
'when build has both archived trace and live trace'
do
let!
(
:build2
)
{
create
(
:ci_build
,
:success
,
:trace_live
,
finished_at:
2
.
days
.
ago
)
}
it
'archives only available targets'
do
subject
build
.
reload
expect
(
build
.
job_artifacts_trace
).
to
be_exist
end
end
end
context
'when a job was failed 2 hours ago'
do
...
...
@@ -40,7 +52,7 @@ describe Ci::RescueStaleLiveTraceWorker do
build
.
update
(
finished_at:
2
.
hours
.
ago
)
end
it_behaves_like
'
schedules to archive traces
'
it_behaves_like
'
archives trace
'
end
context
'when a job was cancelled 2 hours ago'
do
...
...
@@ -50,7 +62,7 @@ describe Ci::RescueStaleLiveTraceWorker do
build
.
update
(
finished_at:
2
.
hours
.
ago
)
end
it_behaves_like
'
schedules to archive traces
'
it_behaves_like
'
archives trace
'
end
context
'when a job has been finished 10 minutes ago'
do
...
...
@@ -60,12 +72,12 @@ describe Ci::RescueStaleLiveTraceWorker do
build
.
update
(
finished_at:
10
.
minutes
.
ago
)
end
it_behaves_like
'does not
schedule to archive traces
'
it_behaves_like
'does not
archive trace
'
end
context
'when a job is running'
do
let!
(
:build
)
{
create
(
:ci_build
,
:running
,
:trace_live
)
}
it_behaves_like
'does not
schedule to archive traces
'
it_behaves_like
'does not
archive trace
'
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