2018-01-29 16:56:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-06 12:40:50 +00:00
|
|
|
describe ArchiveTraceWorker do
|
2018-01-29 16:56:12 +00:00
|
|
|
describe '#perform' do
|
2018-01-31 14:48:48 +00:00
|
|
|
subject { described_class.new.perform(job&.id) }
|
2018-01-29 16:56:12 +00:00
|
|
|
|
|
|
|
context 'when job is found' do
|
|
|
|
let(:job) { create(:ci_build) }
|
|
|
|
|
|
|
|
it 'executes service' do
|
2018-02-28 09:48:08 +00:00
|
|
|
expect_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!)
|
2018-01-29 16:56:12 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not found' do
|
|
|
|
let(:job) { nil }
|
|
|
|
|
|
|
|
it 'does not execute service' do
|
2018-02-28 09:48:08 +00:00
|
|
|
expect_any_instance_of(Gitlab::Ci::Trace).not_to receive(:archive!)
|
2018-01-29 16:56:12 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
2018-11-29 05:34:14 +00:00
|
|
|
|
|
|
|
context 'when an unexpected exception happened during archiving' do
|
|
|
|
let!(:job) { create(:ci_build, :success, :trace_live) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive_stream!).and_raise('Unexpected error')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'increments Prometheus counter, sends crash report to Sentry and ignore an error for continuing to archive' do
|
|
|
|
expect(Gitlab::Sentry)
|
|
|
|
.to receive(:track_exception)
|
|
|
|
.with(RuntimeError,
|
|
|
|
issue_url: 'https://gitlab.com/gitlab-org/gitlab-ce/issues/51502',
|
|
|
|
extra: { job_id: job.id } ).once
|
|
|
|
|
|
|
|
expect(Rails.logger)
|
|
|
|
.to receive(:error)
|
|
|
|
.with("Failed to archive trace. id: #{job.id} message: Unexpected error")
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
expect(Gitlab::Metrics)
|
|
|
|
.to receive(:counter)
|
|
|
|
.with(:job_trace_archive_failed_total, "Counter of failed attempts of trace archiving")
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2018-01-29 16:56:12 +00:00
|
|
|
end
|
|
|
|
end
|