diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-05 10:56:15 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-05 10:56:15 +0900 |
commit | 254134fbb5557caa95c93876a4131c1c5afaf91f (patch) | |
tree | 639cf7bd4ec217ce6f2cc38e508176eefaeedc72 | |
parent | 68d5793985d36fc649cf7bc0e81b5ef988bca8b1 (diff) | |
download | gitlab-ce-254134fbb5557caa95c93876a4131c1c5afaf91f.tar.gz |
Prevent WRITE opetaions if it's already archived
-rw-r--r-- | lib/gitlab/ci/trace.rb | 5 | ||||
-rw-r--r-- | spec/support/shared_examples/ci_trace_shared_examples.rb | 22 | ||||
-rw-r--r-- | spec/workers/ci/archive_traces_cron_worker_spec.rb | 2 |
3 files changed, 27 insertions, 2 deletions
diff --git a/lib/gitlab/ci/trace.rb b/lib/gitlab/ci/trace.rb index a52d71225bb..6a65cec5f03 100644 --- a/lib/gitlab/ci/trace.rb +++ b/lib/gitlab/ci/trace.rb @@ -6,6 +6,7 @@ module Gitlab LEASE_TIMEOUT = 1.hour ArchiveError = Class.new(StandardError) + WriteError = Class.new(StandardError) attr_reader :job @@ -81,7 +82,9 @@ module Gitlab def write(mode) stream = Gitlab::Ci::Trace::Stream.new do - if current_path + if trace_artifact + raise WriteError, 'Already archived' + elsif current_path File.open(current_path, mode) elsif Feature.enabled?('ci_enable_live_trace') Gitlab::Ci::Trace::ChunkedIO.new(job) diff --git a/spec/support/shared_examples/ci_trace_shared_examples.rb b/spec/support/shared_examples/ci_trace_shared_examples.rb index db723a323f8..cf2d63c8bc0 100644 --- a/spec/support/shared_examples/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/ci_trace_shared_examples.rb @@ -138,6 +138,28 @@ shared_examples_for 'common trace features' do end end + describe '#write' do + subject { trace.send(:write, mode) { } } + + let(:mode) { 'wb' } + + context 'when arhicved trace does not exist yet' do + it 'does not raise an error' do + expect { subject }.not_to raise_error + end + end + + context 'when arhicved trace already exists' do + before do + create(:ci_job_artifact, :trace, job: build) + end + + it 'raises an error' do + expect { subject }.to raise_error('Already archived') + end + end + end + describe '#set' do before do trace.set("12") diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb index d9613671cf3..23f5dda298a 100644 --- a/spec/workers/ci/archive_traces_cron_worker_spec.rb +++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb @@ -31,7 +31,7 @@ describe Ci::ArchiveTracesCronWorker do it_behaves_like 'archives trace' context 'when a trace had already been archived' do - let!(:build) { create(:ci_build, :success, :trace_artifact, :trace_live) } + let!(:build) { create(:ci_build, :success, :trace_live, :trace_artifact) } let!(:build2) { create(:ci_build, :success, :trace_live) } it 'continues to archive live traces' do |