diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-11-29 08:51:03 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-11-29 08:51:03 +0300 |
commit | af5bf56857bd6e88bc9ea3322a0873ff6767de69 (patch) | |
tree | 206afaf4ef6cbe958d69d730f179651d621302c2 | |
parent | 3fbd48e127053517e9ee0f6307989758a4d59f9a (diff) |
Improve spec
-rw-r--r-- | spec/services/ci/archive_trace_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/workers/archive_trace_worker_spec.rb | 36 | ||||
-rw-r--r-- | spec/workers/ci/archive_traces_cron_worker_spec.rb | 35 |
3 files changed, 24 insertions, 59 deletions
diff --git a/spec/services/ci/archive_trace_service_spec.rb b/spec/services/ci/archive_trace_service_spec.rb index 6389d7a921f..989aab60113 100644 --- a/spec/services/ci/archive_trace_service_spec.rb +++ b/spec/services/ci/archive_trace_service_spec.rb @@ -11,6 +11,18 @@ describe Ci::ArchiveTraceService, '#execute' do expect(job.reload.job_artifacts_trace).to be_exist end + + context 'when trace is already archived' do + let!(:job) { create(:ci_build, :success, :trace_artifact) } + + it 'ignores an exception' do + expect { subject }.not_to raise_error + end + + it 'does not create an archived trace' do + expect { subject }.not_to change { Ci::JobArtifact.trace.count } + end + end end context 'when job is running' do diff --git a/spec/workers/archive_trace_worker_spec.rb b/spec/workers/archive_trace_worker_spec.rb index ce71468202f..7244ad4f199 100644 --- a/spec/workers/archive_trace_worker_spec.rb +++ b/spec/workers/archive_trace_worker_spec.rb @@ -5,10 +5,11 @@ describe ArchiveTraceWorker do subject { described_class.new.perform(job&.id) } context 'when job is found' do - let(:job) { create(:ci_build) } + let(:job) { create(:ci_build, :trace_live) } it 'executes service' do - expect_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!) + expect_any_instance_of(Ci::ArchiveTraceService) + .to receive(:execute).with(job) subject end @@ -18,38 +19,11 @@ describe ArchiveTraceWorker do let(:job) { nil } it 'does not execute service' do - expect_any_instance_of(Gitlab::Ci::Trace).not_to receive(:archive!) + expect_any_instance_of(Ci::ArchiveTraceService) + .not_to receive(:execute) subject end end - - 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 end end diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb index 8cd1c7e3906..4ba3d436e94 100644 --- a/spec/workers/ci/archive_traces_cron_worker_spec.rb +++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb @@ -30,6 +30,13 @@ describe Ci::ArchiveTracesCronWorker do it_behaves_like 'archives trace' + it 'executes service' do + expect_any_instance_of(Ci::ArchiveTraceService) + .to receive(:execute).with(build) + + subject + end + context 'when a trace had already been archived' do let!(:build) { create(:ci_build, :success, :trace_live, :trace_artifact) } let!(:build2) { create(:ci_build, :success, :trace_live) } @@ -41,34 +48,6 @@ describe Ci::ArchiveTracesCronWorker do 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_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: build.id } ).once - - expect(Rails.logger) - .to receive(:error) - .with("Failed to archive trace. id: #{build.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 end context 'when a job was cancelled' do |