Commit 254134fb authored by Shinya Maeda's avatar Shinya Maeda

Prevent WRITE opetaions if it's already archived

parent 68d57939
......@@ -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)
......
......@@ -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")
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment