summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb67
1 files changed, 55 insertions, 12 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb
index 8b4ecd7d5ae..a3c67210a4a 100644
--- a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb
@@ -35,8 +35,8 @@ RSpec.shared_examples 'common trace features' do
stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project)
end
- it 'calls ::ApplicationRecord.sticking.unstick_or_continue_sticking' do
- expect(::ApplicationRecord.sticking).to receive(:unstick_or_continue_sticking)
+ it 'calls ::Ci::Build.sticking.unstick_or_continue_sticking' do
+ expect(::Ci::Build.sticking).to receive(:unstick_or_continue_sticking)
.with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id)
.and_call_original
@@ -49,8 +49,8 @@ RSpec.shared_examples 'common trace features' do
stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false)
end
- it 'does not call ::ApplicationRecord.sticking.unstick_or_continue_sticking' do
- expect(::ApplicationRecord.sticking).not_to receive(:unstick_or_continue_sticking)
+ it 'does not call ::Ci::Build.sticking.unstick_or_continue_sticking' do
+ expect(::Ci::Build.sticking).not_to receive(:unstick_or_continue_sticking)
trace.read { |stream| stream }
end
@@ -305,8 +305,8 @@ RSpec.shared_examples 'common trace features' do
stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project)
end
- it 'calls ::ApplicationRecord.sticking.stick' do
- expect(::ApplicationRecord.sticking).to receive(:stick)
+ it 'calls ::Ci::Build.sticking.stick' do
+ expect(::Ci::Build.sticking).to receive(:stick)
.with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id)
.and_call_original
@@ -319,8 +319,8 @@ RSpec.shared_examples 'common trace features' do
stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false)
end
- it 'does not call ::ApplicationRecord.sticking.stick' do
- expect(::ApplicationRecord.sticking).not_to receive(:stick)
+ it 'does not call ::Ci::Build.sticking.stick' do
+ expect(::Ci::Build.sticking).not_to receive(:stick)
subject
end
@@ -808,7 +808,19 @@ RSpec.shared_examples 'trace with enabled live trace feature' do
create(:ci_job_artifact, :trace, job: build)
end
- it { is_expected.to be_truthy }
+ it 'is truthy' do
+ is_expected.to be_truthy
+ end
+ end
+
+ context 'when archived trace record exists but file is not stored' do
+ before do
+ create(:ci_job_artifact, :unarchived_trace_artifact, job: build)
+ end
+
+ it 'is falsy' do
+ is_expected.to be_falsy
+ end
end
context 'when live trace exists' do
@@ -872,13 +884,35 @@ RSpec.shared_examples 'trace with enabled live trace feature' do
build.reload
expect(build.trace.exist?).to be_truthy
- expect(build.job_artifacts_trace).to be_nil
Gitlab::Ci::Trace::ChunkedIO.new(build) do |stream|
expect(stream.read).to eq(trace_raw)
end
end
end
+ shared_examples 'a pre-commit error' do |error:|
+ it_behaves_like 'source trace in ChunkedIO stays intact', error: error
+
+ it 'does not save the trace artifact' do
+ expect { subject }.to raise_error(error)
+
+ build.reload
+ expect(build.job_artifacts_trace).to be_nil
+ end
+ end
+
+ shared_examples 'a post-commit error' do |error:|
+ it_behaves_like 'source trace in ChunkedIO stays intact', error: error
+
+ it 'saves the trace artifact but not the file' do
+ expect { subject }.to raise_error(error)
+
+ build.reload
+ expect(build.job_artifacts_trace).to be_present
+ expect(build.job_artifacts_trace.file.exists?).to be_falsy
+ end
+ end
+
context 'when job does not have trace artifact' do
context 'when trace is stored in ChunkedIO' do
let!(:build) { create(:ci_build, :success, :trace_live) }
@@ -892,7 +926,7 @@ RSpec.shared_examples 'trace with enabled live trace feature' do
allow(IO).to receive(:copy_stream).and_return(0)
end
- it_behaves_like 'source trace in ChunkedIO stays intact', error: Gitlab::Ci::Trace::ArchiveError
+ it_behaves_like 'a pre-commit error', error: Gitlab::Ci::Trace::ArchiveError
end
context 'when failed to create job artifact record' do
@@ -902,7 +936,16 @@ RSpec.shared_examples 'trace with enabled live trace feature' do
.and_return(%w[Error Error])
end
- it_behaves_like 'source trace in ChunkedIO stays intact', error: ActiveRecord::RecordInvalid
+ it_behaves_like 'a pre-commit error', error: ActiveRecord::RecordInvalid
+ end
+
+ context 'when storing the file raises an error' do
+ before do
+ stub_artifacts_object_storage(direct_upload: true)
+ allow_any_instance_of(Ci::JobArtifact).to receive(:store_file!).and_raise(Excon::Error::BadGateway, 'S3 is down lol')
+ end
+
+ it_behaves_like 'a post-commit error', error: Excon::Error::BadGateway
end
end
end