Commit 68d57939 authored by Shinya Maeda's avatar Shinya Maeda

Fix spec

parent d86bed76
......@@ -5,8 +5,8 @@ class ArchiveTraceWorker
include PipelineBackgroundQueue
def perform(job_id)
Ci::Build.find_by(id: job_id).try do |job|
job.trace.archive! unless job.job_artifacts_trace
Ci::Build.without_archived_trace.find_by(id: job_id).try do |job|
job.trace.archive!
end
end
end
......@@ -11,8 +11,10 @@ module Ci
# More details in https://gitlab.com/gitlab-org/gitlab-ce/issues/36791
Ci::Build.finished.with_live_trace.find_each(batch_size: 100) do |build|
begin
build.trace.archive! unless build.job_artifacts_trace
build.trace.archive!
rescue => e
next if e.message.include?('Already archived')
failed_archive_counter.increment
Rails.logger.error "Failed to archive stale live trace. id: #{build.id} message: #{e.message}"
end
......
......@@ -13,7 +13,7 @@ module Gitlab
::Ci::Build.finished.without_archived_trace
.where(id: start_id..stop_id).find_each do |build|
begin
build.trace.archive! unless build.job_artifacts_trace
build.trace.archive!
rescue => e
Rails.logger.error "Failed to archive live trace. id: #{build.id} message: #{e.message}"
end
......
......@@ -25,24 +25,36 @@ describe Ci::ArchiveTracesCronWorker do
end
end
context 'when a job was succeeded' do
context 'when a job succeeded' do
let!(:build) { create(:ci_build, :success, :trace_live) }
it_behaves_like 'archives trace'
context 'when archive raised an exception' do
context 'when a trace had already been archived' do
let!(:build) { create(:ci_build, :success, :trace_artifact, :trace_live) }
let!(:build2) { create(:ci_build, :success, :trace_live) }
it 'archives valid targets' do
expect(Rails.logger).to receive(:error).with("Failed to archive stale live trace. id: #{build.id} message: Already archived")
it 'continues to archive live traces' do
subject
build2.reload
expect(build2.job_artifacts_trace).to be_exist
end
end
context 'when an unexpected exception happened during archiving' do
let!(:build) { create(:ci_build, :success, :trace_live) }
before do
allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!).and_raise('Unexpected error')
end
it 'puts a log' do
expect(Rails.logger).to receive(:error).with("Failed to archive stale live trace. id: #{build.id} message: Unexpected error")
subject
end
end
end
context 'when a job was cancelled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment