summaryrefslogtreecommitdiff
path: root/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 13:37:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 13:37:47 +0000
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
downloadgitlab-ce-aee0a117a889461ce8ced6fcf73207fe017f1d99.tar.gz
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb')
-rw-r--r--spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb b/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb
index 6761f052e18..e71f1a4266a 100644
--- a/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb
+++ b/spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb
@@ -53,6 +53,46 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s
log = ActiveRecord::QueryRecorder.new { subject }
expect(log.count).to be_within(1).of(8)
end
+
+ context 'with several locked-unknown artifact records' do
+ before do
+ stub_const("#{described_class}::LOOP_LIMIT", 10)
+ stub_const("#{described_class}::BATCH_SIZE", 2)
+ end
+
+ let!(:lockable_artifact_records) do
+ [
+ create(:ci_job_artifact, :metadata, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: locked_job),
+ create(:ci_job_artifact, :junit, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: locked_job),
+ create(:ci_job_artifact, :sast, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: locked_job),
+ create(:ci_job_artifact, :cobertura, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: locked_job),
+ create(:ci_job_artifact, :trace, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: locked_job)
+ ]
+ end
+
+ let!(:unlockable_artifact_records) do
+ [
+ create(:ci_job_artifact, :metadata, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: job),
+ create(:ci_job_artifact, :junit, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: job),
+ create(:ci_job_artifact, :sast, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: job),
+ create(:ci_job_artifact, :cobertura, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: job),
+ create(:ci_job_artifact, :trace, :expired, locked: ::Ci::JobArtifact.lockeds[:unknown], job: job),
+ artifact
+ ]
+ end
+
+ it 'updates the locked status of job artifacts from artifacts-locked pipelines' do
+ subject
+
+ expect(lockable_artifact_records).to be_all(&:persisted?)
+ expect(lockable_artifact_records).to be_all { |artifact| artifact.reload.artifact_artifacts_locked? }
+ end
+
+ it 'unlocks and then destroys job artifacts from artifacts-unlocked pipelines' do
+ expect { subject }.to change { Ci::JobArtifact.count }.by(-6)
+ expect(Ci::JobArtifact.where(id: unlockable_artifact_records.map(&:id))).to be_empty
+ end
+ end
end
end