Commit 62602469 authored by drew cimino's avatar drew cimino

Use a control for comparison in N+1 spec

parent 59b0cda6
...@@ -19,8 +19,23 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s ...@@ -19,8 +19,23 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s
let!(:artifact) { create(:ci_job_artifact, :expired, job: job, locked: job.pipeline.locked) } let!(:artifact) { create(:ci_job_artifact, :expired, job: job, locked: job.pipeline.locked) }
context 'with preloaded relationships' do context 'with preloaded relationships' do
let(:second_artifact) { create(:ci_job_artifact, :expired, :junit, job: job) }
let(:more_artifacts) do
[
create(:ci_job_artifact, :expired, :sast, job: job),
create(:ci_job_artifact, :expired, :metadata, job: job),
create(:ci_job_artifact, :expired, :codequality, job: job),
create(:ci_job_artifact, :expired, :accessibility, job: job)
]
end
before do before do
stub_const("#{described_class}::LARGE_LOOP_LIMIT", 1) stub_const("#{described_class}::LARGE_LOOP_LIMIT", 1)
# This artifact-with-file is created before the control execution to ensure
# that the DeletedObject operations are accounted for in the query count.
second_artifact
end end
context 'with ci_destroy_unlocked_job_artifacts feature flag disabled' do context 'with ci_destroy_unlocked_job_artifacts feature flag disabled' do
...@@ -28,19 +43,12 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s ...@@ -28,19 +43,12 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s
stub_feature_flags(ci_destroy_unlocked_job_artifacts: false) stub_feature_flags(ci_destroy_unlocked_job_artifacts: false)
end end
it 'performs the smallest number of queries for job_artifacts' do it 'performs a consistent number of queries' do
log = ActiveRecord::QueryRecorder.new { subject } control = ActiveRecord::QueryRecorder.new { service.execute }
# SELECT expired ci_job_artifacts - 3 queries from each_batch more_artifacts
# PRELOAD projects, routes, project_statistics
# BEGIN
# INSERT into ci_deleted_objects
# DELETE loaded ci_job_artifacts
# DELETE security_findings -- for EE
# COMMIT
# SELECT next expired ci_job_artifacts
expect(log.count).to be_within(1).of(10) expect { subject }.not_to exceed_query_limit(control.count)
end end
end end
...@@ -49,9 +57,12 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s ...@@ -49,9 +57,12 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s
stub_feature_flags(ci_destroy_unlocked_job_artifacts: true) stub_feature_flags(ci_destroy_unlocked_job_artifacts: true)
end end
it 'performs the smallest number of queries for job_artifacts' do it 'performs a consistent number of queries' do
log = ActiveRecord::QueryRecorder.new { subject } control = ActiveRecord::QueryRecorder.new { service.execute }
expect(log.count).to be_within(1).of(8)
more_artifacts
expect { subject }.not_to exceed_query_limit(control.count)
end end
end end
end end
......
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