diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/services/ci/destroy_expired_job_artifacts_service_spec.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/services/ci/destroy_expired_job_artifacts_service_spec.rb')
-rw-r--r-- | spec/services/ci/destroy_expired_job_artifacts_service_spec.rb | 76 |
1 files changed, 27 insertions, 49 deletions
diff --git a/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb b/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb index c8d426ee657..1edcef2977b 100644 --- a/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb +++ b/spec/services/ci/destroy_expired_job_artifacts_service_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared describe '.execute' do subject { service.execute } - let_it_be(:artifact, reload: true) do + let_it_be(:artifact, refind: true) do create(:ci_job_artifact, expire_at: 1.day.ago) end @@ -30,14 +30,16 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared it 'performs the smallest number of queries for job_artifacts' do log = ActiveRecord::QueryRecorder.new { subject } - # SELECT expired ci_job_artifacts + # SELECT expired ci_job_artifacts - 3 queries from each_batch # PRELOAD projects, routes, project_statistics # BEGIN # INSERT into ci_deleted_objects # DELETE loaded ci_job_artifacts # DELETE security_findings -- for EE # COMMIT - expect(log.count).to be_within(1).of(8) + # SELECT next expired ci_job_artifacts + + expect(log.count).to be_within(1).of(11) end end @@ -162,13 +164,21 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared end context 'when timeout happens' do + let!(:second_artifact) { create(:ci_job_artifact, expire_at: 1.day.ago) } + before do - stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_TIMEOUT', 1.second) - allow_any_instance_of(described_class).to receive(:destroy_artifacts_batch) { true } + stub_const('Ci::DestroyExpiredJobArtifactsService::LOOP_TIMEOUT', 0.seconds) + stub_const('Ci::DestroyExpiredJobArtifactsService::BATCH_SIZE', 1) + + second_artifact.job.pipeline.unlocked! + end + + it 'destroys one artifact' do + expect { subject }.to change { Ci::JobArtifact.count }.by(-1) end - it 'returns false and does not continue destroying' do - is_expected.to be_falsy + it 'reports the number of destroyed artifacts' do + is_expected.to eq(1) end end @@ -182,13 +192,13 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared let!(:second_artifact) { create(:ci_job_artifact, expire_at: 1.day.ago) } - it 'raises an error and does not continue destroying' do - is_expected.to be_falsy - end - it 'destroys one artifact' do expect { subject }.to change { Ci::JobArtifact.count }.by(-1) end + + it 'reports the number of destroyed artifacts' do + is_expected.to eq(1) + end end context 'when there are no artifacts' do @@ -199,6 +209,10 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared it 'does not raise error' do expect { subject }.not_to raise_error end + + it 'reports the number of destroyed artifacts' do + is_expected.to eq(0) + end end context 'when there are artifacts more than batch sizes' do @@ -213,33 +227,9 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared it 'destroys all expired artifacts' do expect { subject }.to change { Ci::JobArtifact.count }.by(-2) end - end - - context 'when artifact is a pipeline artifact' do - context 'when artifacts are expired' do - let!(:pipeline_artifact_1) { create(:ci_pipeline_artifact, expire_at: 1.week.ago) } - let!(:pipeline_artifact_2) { create(:ci_pipeline_artifact, expire_at: 1.week.ago) } - before do - [pipeline_artifact_1, pipeline_artifact_2].each { |pipeline_artifact| pipeline_artifact.pipeline.unlocked! } - end - - it 'destroys pipeline artifacts' do - expect { subject }.to change { Ci::PipelineArtifact.count }.by(-2) - end - end - - context 'when artifacts are not expired' do - let!(:pipeline_artifact_1) { create(:ci_pipeline_artifact, expire_at: 2.days.from_now) } - let!(:pipeline_artifact_2) { create(:ci_pipeline_artifact, expire_at: 2.days.from_now) } - - before do - [pipeline_artifact_1, pipeline_artifact_2].each { |pipeline_artifact| pipeline_artifact.pipeline.unlocked! } - end - - it 'does not destroy pipeline artifacts' do - expect { subject }.not_to change { Ci::PipelineArtifact.count } - end + it 'reports the number of destroyed artifacts' do + is_expected.to eq(2) end end @@ -255,16 +245,4 @@ RSpec.describe Ci::DestroyExpiredJobArtifactsService, :clean_gitlab_redis_shared end end end - - describe '.destroy_job_artifacts_batch' do - it 'returns a falsy value without artifacts' do - expect(service.send(:destroy_job_artifacts_batch)).to be_falsy - end - end - - describe '.destroy_pipeline_artifacts_batch' do - it 'returns a falsy value without artifacts' do - expect(service.send(:destroy_pipeline_artifacts_batch)).to be_falsy - end - end end |