Commit 356bf3af authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add a test for `ci_environments_status` Gitaly N+1

parent 476c9f0b
...@@ -870,22 +870,19 @@ describe Projects::MergeRequestsController do ...@@ -870,22 +870,19 @@ describe Projects::MergeRequestsController do
end end
end end
# we're trying to reduce the overall number of queries for this method. context 'when multiple environments with deployments are present' do
# set a hard limit for now. https://gitlab.com/gitlab-org/gitlab-ce/issues/52287 let(:another_environment) { create(:environment, project: forked) }
it 'keeps queries in check' do
control_count = ActiveRecord::QueryRecorder.new { get_ci_environments_status }.count
expect(control_count).to be <= 137
end
it 'has no N+1 issues for environments', :request_store, retry: 0 do it 'has no N+1 SQL issues for environments', :request_store, retry: 0 do
# First run to insert test data from lets, which does take up some 30 queries # First run to insert test data from lets, which does take up some 30 queries
get_ci_environments_status get_ci_environments_status
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get_ci_environments_status }.count control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get_ci_environments_status }.count
environment2 = create(:environment, project: forked) create(:deployment, :succeed, environment: another_environment,
create(:deployment, :succeed, environment: environment2, sha: sha, ref: 'master', deployable: build) sha: sha,
ref: 'master',
deployable: build)
# TODO address the last 11 queries # TODO address the last 11 queries
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952 (5 queries) # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952 (5 queries)
...@@ -894,6 +891,27 @@ describe Projects::MergeRequestsController do ...@@ -894,6 +891,27 @@ describe Projects::MergeRequestsController do
expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway) expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway)
end end
it 'has no N+1 Gitaly requests for deployments', :request_store do
expect(merge_request).to be_present
create(:deployment, :succeed, environment: another_environment,
sha: sha,
ref: 'master',
deployable: build)
expect { get_ci_environments_status }
.not_to change { Gitlab::GitalyClient.get_request_count }
end
end
# we're trying to reduce the overall number of queries for this method.
# set a hard limit for now. https://gitlab.com/gitlab-org/gitlab-ce/issues/52287
it 'keeps queries in check' do
control_count = ActiveRecord::QueryRecorder.new { get_ci_environments_status }.count
expect(control_count).to be <= 137
end
def get_ci_environments_status(extra_params = {}) def get_ci_environments_status(extra_params = {})
params = { params = {
namespace_id: merge_request.project.namespace.to_param, namespace_id: merge_request.project.namespace.to_param,
......
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