Prevent WRITE opetaions if it's already archived
This commit is contained in:
parent
68d5793985
commit
254134fbb5
|
@ -6,6 +6,7 @@ module Gitlab
|
||||||
LEASE_TIMEOUT = 1.hour
|
LEASE_TIMEOUT = 1.hour
|
||||||
|
|
||||||
ArchiveError = Class.new(StandardError)
|
ArchiveError = Class.new(StandardError)
|
||||||
|
WriteError = Class.new(StandardError)
|
||||||
|
|
||||||
attr_reader :job
|
attr_reader :job
|
||||||
|
|
||||||
|
@ -81,7 +82,9 @@ module Gitlab
|
||||||
|
|
||||||
def write(mode)
|
def write(mode)
|
||||||
stream = Gitlab::Ci::Trace::Stream.new do
|
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)
|
File.open(current_path, mode)
|
||||||
elsif Feature.enabled?('ci_enable_live_trace')
|
elsif Feature.enabled?('ci_enable_live_trace')
|
||||||
Gitlab::Ci::Trace::ChunkedIO.new(job)
|
Gitlab::Ci::Trace::ChunkedIO.new(job)
|
||||||
|
|
|
@ -138,6 +138,28 @@ shared_examples_for 'common trace features' do
|
||||||
end
|
end
|
||||||
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
|
describe '#set' do
|
||||||
before do
|
before do
|
||||||
trace.set("12")
|
trace.set("12")
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe Ci::ArchiveTracesCronWorker do
|
||||||
it_behaves_like 'archives trace'
|
it_behaves_like 'archives trace'
|
||||||
|
|
||||||
context 'when a trace had already been archived' do
|
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) }
|
let!(:build2) { create(:ci_build, :success, :trace_live) }
|
||||||
|
|
||||||
it 'continues to archive live traces' do
|
it 'continues to archive live traces' do
|
||||||
|
|
Loading…
Reference in New Issue