Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/ci/archive_trace_service_spec.rb')
-rw-r--r--spec/services/ci/archive_trace_service_spec.rb67
1 files changed, 66 insertions, 1 deletions
diff --git a/spec/services/ci/archive_trace_service_spec.rb b/spec/services/ci/archive_trace_service_spec.rb
index 359ea0699e4..3fb9d092ae7 100644
--- a/spec/services/ci/archive_trace_service_spec.rb
+++ b/spec/services/ci/archive_trace_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Ci::ArchiveTraceService, '#execute' do
+RSpec.describe Ci::ArchiveTraceService, '#execute', feature_category: :continuous_integration do
subject { described_class.new.execute(job, worker_name: Ci::ArchiveTraceWorker.name) }
context 'when job is finished' do
@@ -192,4 +192,69 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do
expect(job.trace_metadata.archival_attempts).to eq(1)
end
end
+
+ describe '#batch_execute' do
+ subject { described_class.new.batch_execute(worker_name: Ci::ArchiveTraceWorker.name) }
+
+ let_it_be_with_reload(:job) { create(:ci_build, :success, :trace_live, finished_at: 1.day.ago) }
+ let_it_be_with_reload(:job2) { create(:ci_build, :success, :trace_live, finished_at: 1.day.ago) }
+
+ it 'archives multiple traces' do
+ expect { subject }.not_to raise_error
+
+ expect(job.reload.job_artifacts_trace).to be_exist
+ expect(job2.reload.job_artifacts_trace).to be_exist
+ end
+
+ it 'processes traces independently' do
+ allow_next_instance_of(Gitlab::Ci::Trace) do |instance|
+ orig_method = instance.method(:archive!)
+ allow(instance).to receive(:archive!) do
+ raise('Unexpected error') if instance.job.id == job.id
+
+ orig_method.call
+ end
+ end
+
+ expect { subject }.not_to raise_error
+
+ expect(job.reload.job_artifacts_trace).to be_nil
+ expect(job2.reload.job_artifacts_trace).to be_exist
+ end
+
+ context 'when timeout is reached' do
+ before do
+ stub_const("#{described_class}::LOOP_TIMEOUT", 0.seconds)
+ end
+
+ it 'stops executing traces' do
+ expect { subject }.not_to raise_error
+
+ expect(job.reload.job_artifacts_trace).to be_nil
+ end
+ end
+
+ context 'when loop limit is reached' do
+ before do
+ stub_const("#{described_class}::LOOP_LIMIT", -1)
+ end
+
+ it 'skips archiving' do
+ expect(job.trace).not_to receive(:archive!)
+
+ subject
+ end
+
+ it 'stops executing traces' do
+ expect(Sidekiq.logger).to receive(:warn).with(
+ class: Ci::ArchiveTraceWorker.name,
+ message: "Loop limit reached.",
+ job_id: job.id)
+
+ expect { subject }.not_to raise_error
+
+ expect(job.reload.job_artifacts_trace).to be_nil
+ end
+ end
+ end
end