Prevent WRITE opetaions if it's already archived

This commit is contained in:
Shinya Maeda 2018-07-05 10:56:15 +09:00
parent 68d5793985
commit 254134fbb5
3 changed files with 27 additions and 2 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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