Commit c6d9e714 authored by Marius Bobin's avatar Marius Bobin

Merge branch 'add-explicit-trace-guard' into 'master'

Add explicit trace guard

See merge request gitlab-org/gitlab!84099
parents b0f8a7a4 0f39968d
......@@ -127,7 +127,9 @@ module Ci
def wrongly_expired?(artifact)
return false unless artifact.expire_at.present?
match_date?(artifact.expire_at) && match_time?(artifact.expire_at)
# Although traces should never have expiration dates that don't match time & date here.
# we can explicitly exclude them by type since they should never be destroyed.
artifact.trace? || (match_date?(artifact.expire_at) && match_time?(artifact.expire_at))
end
def match_date?(expire_at)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Ci::JobArtifacts::DestroyBatchService do
let(:artifacts) { Ci::JobArtifact.where(id: [artifact_with_file.id, artifact_without_file.id]) }
let(:artifacts) { Ci::JobArtifact.where(id: [artifact_with_file.id, artifact_without_file.id, trace_artifact.id]) }
let(:service) { described_class.new(artifacts, pick_up_at: Time.current) }
let_it_be(:artifact_with_file, refind: true) do
......@@ -18,6 +18,10 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
create(:ci_job_artifact)
end
let_it_be(:trace_artifact, refind: true) do
create(:ci_job_artifact, :trace, :expired)
end
describe '.execute' do
subject(:execute) { service.execute }
......@@ -42,6 +46,12 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
execute
end
it 'preserves trace artifacts and removes any timestamp' do
expect { subject }
.to change { trace_artifact.reload.expire_at }.from(trace_artifact.expire_at).to(nil)
.and not_change { Ci::JobArtifact.exists?(trace_artifact.id) }
end
context 'ProjectStatistics' do
it 'resets project statistics' do
expect(ProjectStatistics).to receive(:increment_statistic).once
......
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