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

Add a test for `ci_environments_status` Gitaly N+1

parent 476c9f0b
...@@ -870,6 +870,40 @@ describe Projects::MergeRequestsController do ...@@ -870,6 +870,40 @@ describe Projects::MergeRequestsController do
end end
end end
context 'when multiple environments with deployments are present' do
let(:another_environment) { create(:environment, project: forked) }
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
get_ci_environments_status
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get_ci_environments_status }.count
create(:deployment, :succeed, environment: another_environment,
sha: sha,
ref: 'master',
deployable: build)
# TODO address the last 11 queries
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952 (5 queries)
# And https://gitlab.com/gitlab-org/gitlab-ce/issues/64105 (6 queries)
leeway = 11
expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway)
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. # 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 # set a hard limit for now. https://gitlab.com/gitlab-org/gitlab-ce/issues/52287
it 'keeps queries in check' do it 'keeps queries in check' do
...@@ -878,22 +912,6 @@ describe Projects::MergeRequestsController do ...@@ -878,22 +912,6 @@ describe Projects::MergeRequestsController do
expect(control_count).to be <= 137 expect(control_count).to be <= 137
end end
it 'has no N+1 issues for environments', :request_store, retry: 0 do
# First run to insert test data from lets, which does take up some 30 queries
get_ci_environments_status
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get_ci_environments_status }.count
environment2 = create(:environment, project: forked)
create(:deployment, :succeed, environment: environment2, sha: sha, ref: 'master', deployable: build)
# TODO address the last 11 queries
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952 (5 queries)
# And https://gitlab.com/gitlab-org/gitlab-ce/issues/64105 (6 queries)
leeway = 11
expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway)
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